Skip to content

Commit 06f7245

Browse files
committed
Fix format
1 parent 62c7955 commit 06f7245

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

clone-graph/bhyun-kim.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@
2424
- The maximum depth of the recursive call stack is the number of nodes in the graph.
2525
"""
2626

27+
2728
# Definition for a Node.
2829
class Node:
29-
def __init__(self, val = 0, neighbors = None):
30+
def __init__(self, val=0, neighbors=None):
3031
self.val = val
3132
self.neighbors = neighbors if neighbors is not None else []
3233

34+
3335
from typing import Optional
3436

37+
3538
class Solution:
36-
def cloneGraph(self, node: Optional['Node']) -> Optional['Node']:
39+
def cloneGraph(self, node: Optional["Node"]) -> Optional["Node"]:
3740
if not node:
3841
return None
3942

@@ -51,4 +54,4 @@ def dfs(node):
5154

5255
return clone
5356

54-
return dfs(node)
57+
return dfs(node)

course-schedule/bhyun-kim.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from collections import defaultdict
3232
from typing import List
3333

34+
3435
class Solution:
3536
def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
3637
adj_list = defaultdict(list)
@@ -45,18 +46,18 @@ def has_cycle(v):
4546
return True
4647
if state[v] == 2: # Node has been visited, no cycle here
4748
return False
48-
49+
4950
state[v] = 1
5051
for neighbor in adj_list[v]:
5152
if has_cycle(neighbor):
5253
return True
53-
54+
5455
state[v] = 2
5556
return False
5657

5758
for course in range(numCourses):
5859
if state[course] == 0:
5960
if has_cycle(course):
6061
return False
61-
62-
return True
62+
63+
return True

design-add-and-search-words-data-structure/bhyun-kim.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
- We use a trie data structure to store the words.
3030
"""
3131

32+
3233
class TrieNode:
3334
def __init__(self):
3435
self.children = {}
3536
self.is_end_of_word = False
3637

38+
3739
class WordDictionary:
3840
def __init__(self):
3941
self.root = TrieNode()
@@ -50,7 +52,7 @@ def search(self, word):
5052
def dfs(j, node):
5153
for i in range(j, len(word)):
5254
char = word[i]
53-
if char == '.':
55+
if char == ".":
5456
for child in node.children.values():
5557
if dfs(i + 1, child):
5658
return True
@@ -60,5 +62,5 @@ def dfs(j, node):
6062
return False
6163
node = node.children[char]
6264
return node.is_end_of_word
63-
64-
return dfs(0, self.root)
65+
66+
return dfs(0, self.root)

number-of-islands/bhyun-kim.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from typing import List
2525

26+
2627
class Solution:
2728
def numIslands(self, grid: List[List[str]]) -> int:
2829
if not grid:
@@ -33,22 +34,19 @@ def numIslands(self, grid: List[List[str]]) -> int:
3334
island_count = 0
3435

3536
def dfs(i, j):
36-
if i < 0 or i >= m or j < 0 or j >= n or grid[i][j] != '1':
37+
if i < 0 or i >= m or j < 0 or j >= n or grid[i][j] != "1":
3738
return
38-
grid[i][j] = '#'
39+
grid[i][j] = "#"
3940

40-
dfs(i - 1, j)
41-
dfs(i + 1, j)
42-
dfs(i, j - 1)
43-
dfs(i, j + 1)
41+
dfs(i - 1, j)
42+
dfs(i + 1, j)
43+
dfs(i, j - 1)
44+
dfs(i, j + 1)
4445

4546
for i in range(m):
4647
for j in range(n):
47-
48-
if grid[i][j] == '1':
48+
if grid[i][j] == "1":
4949
dfs(i, j)
5050
island_count += 1
5151

5252
return island_count
53-
54-

pacific-atlantic-water-flow/bhyun-kim.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
from typing import List
2525

26+
2627
class Solution:
2728
def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:
28-
2929
if not heights or not heights[0]:
3030
return []
3131

@@ -34,7 +34,12 @@ def dfs(matrix, reachable, x, y):
3434
reachable.add((x, y))
3535
for dx, dy in directions:
3636
nx, ny = x + dx, y + dy
37-
if 0 <= nx < m and 0 <= ny < n and (nx, ny) not in reachable and matrix[nx][ny] >= matrix[x][y]:
37+
if (
38+
0 <= nx < m
39+
and 0 <= ny < n
40+
and (nx, ny) not in reachable
41+
and matrix[nx][ny] >= matrix[x][y]
42+
):
3843
dfs(matrix, reachable, nx, ny)
3944

4045
m, n = len(heights), len(heights[0])
@@ -49,4 +54,4 @@ def dfs(matrix, reachable, x, y):
4954
dfs(heights, pacific_reachable, 0, j)
5055
dfs(heights, atlantic_reachable, m - 1, j)
5156

52-
return list(pacific_reachable & atlantic_reachable)
57+
return list(pacific_reachable & atlantic_reachable)

0 commit comments

Comments
 (0)