Skip to content

Commit af84706

Browse files
authored
Update maximum-number-of-moves-in-a-grid.cpp
1 parent fa272a9 commit af84706

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

C++/maximum-number-of-moves-in-a-grid.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class Solution {
66
public:
77
int maxMoves(vector<vector<int>>& grid) {
88
vector<bool> dp(size(grid), true);
9-
for (int c = 0; c < size(grid[0]) - 1; ++c) {
9+
int c = 0;
10+
for (; c < size(grid[0]) - 1; ++c) {
1011
vector<bool> new_dp(size(grid));
1112
for (int r = 0; r < size(grid); ++r) {
1213
if (!dp[r]) {
@@ -24,10 +25,10 @@ class Solution {
2425
}
2526
dp = move(new_dp);
2627
if (!accumulate(cbegin(dp), cend(dp), 0)) {
27-
return c;
28+
break;
2829
}
2930
}
30-
return size(grid[0]) - 1;
31+
return c;
3132
}
3233
};
3334

0 commit comments

Comments
 (0)