1
# Runtime: 205 ms (Top 93.96%) | Memory: 14.3 MB (Top 84.02%)
2

3

4
class Solution:
5
def findBall(self, grid: List[List[int]]) -> List[int]:
6

7
m, n = len(grid), len(grid[0])
8
for i in range(m):
9
grid[i].insert(0, 1)
10
grid[i].append(-1)
11
res = []
12

13
for k in range(1, n + 1):
14
i, j = 0, k
15
struck = False
16
while i < m:
17
if grid[i][j] == 1:
18
if grid[i][j + 1] == 1:
19
j += 1
20
else:
21
struck = True
22
break
23
else:
24
if grid[i][j - 1] == -1:
25
j -= 1
26
else:
27
struck = True
28
break
29
i += 1
30
if struck:
31
res.append(-1)
32
else:
33
res.append(j - 1)
34

35
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0