2022-08-02 11:40:31 +02:00
|
|
|
class Solution {
|
2024-01-03 12:06:42 +01:00
|
|
|
int right(const std::vector<int> &row, int size, int idx) const {
|
2022-08-02 11:40:31 +02:00
|
|
|
if (idx >= size) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return row[idx];
|
|
|
|
}
|
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
public:
|
|
|
|
int uniquePaths(int m, int n) {
|
2022-08-02 11:40:31 +02:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
};
|