clueless coding // TODO: be smarter

LeetCode Unique Paths: CPP Solution



TL;DR Code Solution


int uniquePaths(int m, int n) {
    vector<int> dp(m);
    if (m < 0 || n < 0) {
        return 0;
    }
    dp[0] = 1;

    for (int i = 0; i < n; i++) {
        for (int j = 1; j < m; j++) {
            dp[j] += dp[j-1];
        }
    }

    return dp[m - 1];

}