1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/cpp/unique-paths.cpp
Matej Focko b229608723
cpp(chore): add clang-format style and format
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 12:06:54 +01:00

25 lines
560 B
C++

class Solution {
int right(const std::vector<int> &row, int size, int idx) const {
if (idx >= size) {
return 0;
}
return row[idx];
}
public:
int uniquePaths(int m, int n) {
std::vector<int> bottom(n, 1);
for (int y = m - 2; y >= 0; y--) {
std::vector<int> above(n, 0);
for (int x = n - 1; x >= 0; x--) {
above[x] = right(above, n, x + 1) + bottom[x];
}
bottom = std::move(above);
}
return bottom[0];
}
};