Skip to content

Commit bb0514b

Browse files
committed
style: format code using prettier and black
* prettier --write "**/*.md" * black -S .
1 parent 2d716a9 commit bb0514b

File tree

41 files changed

+228
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+228
-133
lines changed

lcci/02.05.Sum Lists/Solution.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# self.val = x
55
# self.next = None
66

7+
78
class Solution:
89
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
910
dummy = cur = ListNode(0)

lcci/10.10.Rank from Stream/Solution.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def query(self, x):
2121

2222

2323
class StreamRank:
24-
2524
def __init__(self):
2625
self.tree = BinaryIndexedTree(50010)
2726

lcs/LCS 03. 主题空间/Solution.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ def find(x):
1616
else:
1717
for a, b in dirs:
1818
x, y = i + a, j + b
19-
if (grid[x][y] == '0' or grid[i][j] == grid[x][y]) and find(x * n + y) != find(i * n + j):
19+
if (grid[x][y] == '0' or grid[i][j] == grid[x][y]) and find(
20+
x * n + y
21+
) != find(i * n + j):
2022
size[find(x * n + y)] += size[find(i * n + j)]
2123
p[find(i * n + j)] = find(x * n + y)
22-
return max([size[i * n + j] for i in range(m) for j in range(n) if find(i * n + j) != find(m * n)], default=0)
24+
return max(
25+
[
26+
size[i * n + j]
27+
for i in range(m)
28+
for j in range(n)
29+
if find(i * n + j) != find(m * n)
30+
],
31+
default=0,
32+
)

solution/0000-0099/0079.Word Search/Solution.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ def exist(self, board: List[List[str]], word: str) -> bool:
33
def dfs(i, j, cur):
44
if cur == len(word):
55
return True
6-
if i < 0 or i >= m or j < 0 or j >= n or board[i][j] == '0' or word[cur] != board[i][j]:
6+
if (
7+
i < 0
8+
or i >= m
9+
or j < 0
10+
or j >= n
11+
or board[i][j] == '0'
12+
or word[cur] != board[i][j]
13+
):
714
return False
815
t = board[i][j]
916
board[i][j] = '0'

solution/0000-0099/0090.Subsets II/Solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def dfs(u, t):
88
t.append(nums[i])
99
dfs(i + 1, t)
1010
t.pop()
11-
11+
1212
ans = []
1313
nums.sort()
1414
dfs(0, [])

solution/0100-0199/0126.Word Ladder II/Solution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class Solution:
2-
def findLadders(self, beginWord: str, endWord: str, wordList: List[str]) -> List[List[str]]:
2+
def findLadders(
3+
self, beginWord: str, endWord: str, wordList: List[str]
4+
) -> List[List[str]]:
35
def dfs(path, cur):
46
if cur == beginWord:
57
ans.append(path[::-1])

solution/0100-0199/0127.Word Ladder/Solution.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def extend(m1, m2, q):
2525
q1, q2 = deque([beginWord]), deque([endWord])
2626
m1, m2 = {beginWord: 0}, {endWord: 0}
2727
while q1 and q2:
28-
t = extend(m1, m2, q1) if len(q1) <= len(
29-
q2) else extend(m2, m1, q2)
28+
t = extend(m1, m2, q1) if len(q1) <= len(q2) else extend(m2, m1, q2)
3029
if t != -1:
3130
return t + 1
3231
return 0

solution/0100-0199/0130.Surrounded Regions/Solution.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ def solve(self, board: List[List[str]]) -> None:
33
"""
44
Do not return anything, modify board in-place instead.
55
"""
6+
67
def dfs(i, j):
78
board[i][j] = '.'
89
for a, b in [[0, -1], [0, 1], [1, 0], [-1, 0]]:
@@ -13,7 +14,9 @@ def dfs(i, j):
1314
m, n = len(board), len(board[0])
1415
for i in range(m):
1516
for j in range(n):
16-
if board[i][j] == 'O' and (i == 0 or i == m - 1 or j == 0 or j == n - 1):
17+
if board[i][j] == 'O' and (
18+
i == 0 or i == m - 1 or j == 0 or j == n - 1
19+
):
1720
dfs(i, j)
1821
for i in range(m):
1922
for j in range(n):

solution/0300-0399/0307.Range Sum Query - Mutable/Solution.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def query(self, x):
2121

2222

2323
class NumArray:
24-
2524
def __init__(self, nums: List[int]):
2625
self.tree = BinaryIndexedTree(len(nums))
2726
for i, v in enumerate(nums, 1):

solution/0300-0399/0308.Range Sum Query 2D - Mutable/Solution.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def query(self, x):
2121

2222

2323
class NumMatrix:
24-
2524
def __init__(self, matrix: List[List[int]]):
2625
self.trees = []
2726
n = len(matrix[0])
@@ -37,7 +36,10 @@ def update(self, row: int, col: int, val: int) -> None:
3736
tree.update(col + 1, val - prev)
3837

3938
def sumRegion(self, row1: int, col1: int, row2: int, col2: int) -> int:
40-
return sum(tree.query(col2 + 1) - tree.query(col1) for tree in self.trees[row1: row2 + 1])
39+
return sum(
40+
tree.query(col2 + 1) - tree.query(col1)
41+
for tree in self.trees[row1 : row2 + 1]
42+
)
4143

4244

4345
# Your NumMatrix object will be instantiated and called as such:

0 commit comments

Comments
 (0)