尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

1706. Where Will the Ball Fall

1706. Where Will the Ball Fall Problem: 1706. 球会落何处对每一列的输入判断几种情况就可以若grid[y][x]-1, 且 x0, 或者 grid[y][x - 1] 0, 则停止 -1否则x-1若grid[y][x]1, 且 xn-1, 或者 grid[y][x 1] 0, 则停止 -1否则x1Codeclass Solution { public: vectorint findBall(vectorvectorint grid) { int m grid.size(), n grid[0].size(); vectorint ret; int x, y; for(int i 0; i n; i) { x i; y 0; while(y m) { if(grid[y][x] 0) { if((x n - 1) || (grid[y][x 1] 0)) { ret.push_back(-1); break; } else { x 1; } } else { if((x 0) || (grid[y][x - 1] 0)) { ret.push_back(-1); break; } else { x - 1; } } y; } if(y m) { ret.push_back(x); } } return ret; } };
返回列表