Skip to content

Commit 78436f9

Browse files
committed
modified solutions
1 parent a7d03f6 commit 78436f9

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

number-of-islands/haklee.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,13 @@ class Solution:
2424
def numIslands(self, grid: List[List[str]]) -> int:
2525
minx, miny, maxx, maxy = 0, 0, len(grid[0]) - 1, len(grid) - 1
2626

27-
def check_inside(i, j):
28-
# 그리드 안에 있는 칸인지 체크.
29-
return minx <= j <= maxx and miny <= i <= maxy
30-
3127
def remove_ground(i, j):
32-
if grid[i][j] == "1":
28+
if minx <= j <= maxx and miny <= i <= maxy and grid[i][j] == "1":
3329
grid[i][j] = "0"
34-
if check_inside(i - 1, j):
35-
remove_ground(i - 1, j)
36-
if check_inside(i + 1, j):
37-
remove_ground(i + 1, j)
38-
if check_inside(i, j - 1):
39-
remove_ground(i, j - 1)
40-
if check_inside(i, j + 1):
41-
remove_ground(i, j + 1)
30+
remove_ground(i - 1, j)
31+
remove_ground(i + 1, j)
32+
remove_ground(i, j - 1)
33+
remove_ground(i, j + 1)
4234

4335
sol = 0
4436
for i in range(maxy + 1):

set-matrix-zeroes/haklee.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def setZeroes(self, matrix: List[List[int]]) -> None:
2828
if matrix[i][j] == 0:
2929
col_to_change.add(i)
3030
row_to_change.add(j)
31+
3132
for i in col_to_change:
3233
for j in range(n):
3334
matrix[i][j] = 0

0 commit comments

Comments
 (0)