class Solution(object):
def findBall(self, grid):
"""
:type grid: List[List[int]]
:rtype: List[int]
"""
n = len(grid[0])
ans = [-1] * n
for j in range(n):
col = j
for row in grid:
cur_direction = row[col]
col += cur_direction
if col < 0 or col >= n or row[col] != cur_direction:
break
else:
ans[j] = col
return ans