Skip to content

Commit 7e44ff2

Browse files
committed
Update
1 parent 498e2d0 commit 7e44ff2

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Python/Number_Of_Islanda.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def numIslands(self, grid):
2+
"""
3+
:type grid: List[List[str]]
4+
:rtype: int
5+
"""
6+
c = 0
7+
def dfs(i, j, grid):
8+
if i < 0 or j < 0 or i >= len(grid) or j >= len(grid[0]) or grid[i][j] == "0": return
9+
grid[i][j] = "0"
10+
dfs(i - 1, j, grid)
11+
dfs(i + 1, j, grid)
12+
dfs(i, j + 1, grid)
13+
dfs(i, j - 1, grid)
14+
for i, v in enumerate(grid):
15+
for j, u in enumerate(v):
16+
if u == "1": c += 1; dfs(i, j, grid)
17+
return c

Python/Plus_One.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ def plusOne(nums):
1717

1818
print(plusOne([1, 2, 3, 4, 0]))
1919
print(plusOne([9, 9]))
20-
print(plusOne([9, 9, 5, 9]))
20+
print(plusOne([9, 9, 5, 9]))
21+
print(plusOne([0]))

Python/Strobogrammatic_Number.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def isStrobogrammatic(self, num):
2+
"""
3+
:type num: str
4+
:rtype: bool
5+
"""
6+
n2 = ""
7+
updowns = {"6": "9", "8": "8", "9": "6", "0":"0", "1":"1"}
8+
if "7" in num or "5" in num or "3" in num or "4" in num or "2" in num: return False
9+
for i, v in enumerate(num[::-1]):
10+
n2 += updowns[v]
11+
print(n2)
12+
return num == n2

0 commit comments

Comments
 (0)