Skip to content

Commit 2c51a42

Browse files
authored
Create where-will-the-ball-fall.py
1 parent 44897c0 commit 2c51a42

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/where-will-the-ball-fall.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(m * n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def findBall(self, grid):
6+
"""
7+
:type grid: List[List[int]]
8+
:rtype: List[int]
9+
"""
10+
result = []
11+
for c in xrange(len(grid[0])):
12+
for r in xrange(len(grid)):
13+
nc = c+grid[r][c]
14+
if not (0 <= nc < len(grid[0]) and grid[r][nc] == grid[r][c]):
15+
c = -1
16+
break
17+
c = nc
18+
result.append(c)
19+
return result

0 commit comments

Comments
 (0)