原题链接:https://leetcode-cn.com/problems/where-will-the-ball-fall/
class Solution {
public:
vector<int> findBall(vector<vector<int>>& grid) {
int m = grid.size(), n = grid[0].size();
vector<int> res(n, INT_MAX);
for (int j = 0; j < n; ++j) {
int y = j;
for (auto row : grid) {
int dir = row[y];
y += dir;
if (y < 0 || y >= n || row[y] != dir) {
res[j] = -1;
break;
}
res[j] = y;
}
}
return res;
}
};