Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6d106ce

Browse files
committed
update 289
1 parent 8fecd51 commit 6d106ce

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

0289-game-of-life.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
289. Game of Life
33
4-
Submitted: March 17, 2025
4+
Submitted: March 19, 2025
55
6-
Runtime: 2 ms (beats 23.06%)
7-
Memory: 17.70 MB (beats 94.61%)
6+
Runtime: 1 ms (beats 30.59%)
7+
Memory: 17.72 MB (beats 76.77%)
88
"""
99

1010
class Solution:
@@ -16,19 +16,15 @@ def gameOfLife(self, board: List[List[int]]) -> None:
1616

1717
for i in range(len(board)):
1818
for j in range(len(board[0])):
19-
n = self.sumOfNeighbors(board_copy, i, j)
19+
n = sum(
20+
sum(
21+
board_copy[x][y] for y in range(max(0, j - 1), min(len(board_copy[0]), j + 2))
22+
if (x, y) != (i, j)
23+
)
24+
for x in range(max(0, i - 1), min(len(board_copy), i + 2))
25+
)
2026
if board_copy[i][j]:
2127
if n < 2: board[i][j] = 0
2228
elif n > 3: board[i][j] = 0
2329
elif n == 3:
2430
board[i][j] = 1
25-
26-
27-
def sumOfNeighbors(self, board, i, j):
28-
return sum(
29-
sum(
30-
board[x][y] for y in range(max(0, j - 1), min(len(board[0]), j + 2))
31-
if (x, y) != (i, j)
32-
)
33-
for x in range(max(0, i - 1), min(len(board), i + 2))
34-
)

0 commit comments

Comments
 (0)