Skip to content

Commit 9aa9f8c

Browse files
authored
Create grid-game.py
1 parent a38a947 commit 9aa9f8c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/grid-game.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
import itertools
5+
6+
7+
class Solution(object):
8+
def gridGame(self, grid):
9+
"""
10+
:type grid: List[List[int]]
11+
:rtype: int
12+
"""
13+
result = float("inf")
14+
left, right = 0, sum(grid[0])
15+
for a, b in itertools.izip(grid[0], grid[1]):
16+
right -= a
17+
result = min(result, max(left, right))
18+
left += b
19+
return result

0 commit comments

Comments
 (0)