Skip to content

Commit 41118c7

Browse files
authored
style: format python code in markdown files (doocs#1040)
1 parent 01cf6af commit 41118c7

File tree

244 files changed

+17104
-16780
lines changed

Some content is hidden

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

244 files changed

+17104
-16780
lines changed

Pipfile

-12
This file was deleted.

Pipfile.lock

-134
This file was deleted.

lcci/16.19.Pond Sizes/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ p[find(a)] = find(b)
5656
p = list(range(n))
5757
size = [1] * n
5858

59+
5960
# 返回x的祖宗节点
6061
def find(x):
6162
if p[x] != x:
6263
# 路径压缩
6364
p[x] = find(p[x])
6465
return p[x]
6566

67+
6668
# 合并a和b所在的两个集合
6769
if find(a) != find(b):
6870
size[find(b)] += size[find(a)]
@@ -76,6 +78,7 @@ if find(a) != find(b):
7678
p = list(range(n))
7779
d = [0] * n
7880

81+
7982
# 返回x的祖宗节点
8083
def find(x):
8184
if p[x] != x:
@@ -84,6 +87,7 @@ def find(x):
8487
p[x] = t
8588
return p[x]
8689

90+
8791
# 合并a和b所在的两个集合
8892
p[find(a)] = find(b)
8993
d[find(a)] = distance

lcof/面试题06. 从尾到头打印链表/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Solution:
5959
# self.val = x
6060
# self.next = None
6161

62+
6263
class Solution:
6364
def reversePrint(self, head: ListNode) -> List[int]:
6465
if head is None:

lcof/面试题24. 反转链表/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Solution:
6666
# self.val = x
6767
# self.next = None
6868

69+
6970
class Solution:
7071
def reverseList(self, head: ListNode) -> ListNode:
7172
if head is None or head.next is None:

lcof/面试题25. 合并两个排序的链表/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class Solution:
7272
# self.val = x
7373
# self.next = None
7474

75+
7576
class Solution:
7677
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
7778
if l1 is None or l2 is None:

lcof/面试题27. 二叉树的镜像/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Solution:
7474
# self.left = None
7575
# self.right = None
7676

77+
7778
class Solution:
7879
def mirrorTree(self, root: TreeNode) -> TreeNode:
7980
if root is None:

lcof/面试题51. 数组中的逆序对/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class BinaryIndexedTree:
9494
x -= x & -x
9595
return s
9696

97+
9798
class Solution:
9899
def reversePairs(self, nums: List[int]) -> int:
99100
alls = sorted(set(nums))

lcof/面试题55 - I. 二叉树的深度/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Solution:
6262
# self.left = None
6363
# self.right = None
6464

65+
6566
class Solution:
6667
def maxDepth(self, root: TreeNode) -> int:
6768
def dfs(root):

lcof/面试题68 - I. 二叉搜索树的最近公共祖先/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ class Solution:
8484
# self.left = None
8585
# self.right = None
8686

87+
8788
class Solution:
88-
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
89+
def lowestCommonAncestor(
90+
self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode'
91+
) -> 'TreeNode':
8992
if root.val < p.val and root.val < q.val:
9093
return self.lowestCommonAncestor(root.right, p, q)
9194
if root.val > p.val and root.val > q.val:

lcof2/剑指 Offer II 017. 含有所有字符的最短字符串/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class Solution:
128128
if window[ch] == need[ch]:
129129
windowCount -= 1
130130
window[ch] -= 1
131-
return "" if minLen == inf else s[start:start + minLen]
131+
return "" if minLen == inf else s[start : start + minLen]
132132
```
133133

134134
### **Java**

lcof2/剑指 Offer II 041. 滑动窗口的平均值/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class MovingAverage:
8282

8383
```python
8484
class MovingAverage:
85-
8685
def __init__(self, size: int):
8786
self.n = size
8887
self.s = 0

lcof2/剑指 Offer II 055. 二叉搜索树迭代器/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class BSTIterator:
132132
# self.left = left
133133
# self.right = right
134134
class BSTIterator:
135-
136135
def __init__(self, root: TreeNode):
137136
self.stack = []
138137
while root:

lcof2/剑指 Offer II 067. 最大的异或/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class Trie:
132132
node = node.children[v]
133133
return res
134134

135+
135136
class Solution:
136137
def findMaximumXOR(self, nums: List[int]) -> int:
137138
trie = Trie()

lcof2/剑指 Offer II 105. 岛屿的最大面积/README.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ p[find(a)] = find(b)
7878
p = list(range(n))
7979
size = [1] * n
8080

81+
8182
# 返回x的祖宗节点
8283
def find(x):
8384
if p[x] != x:
8485
# 路径压缩
8586
p[x] = find(p[x])
8687
return p[x]
8788

89+
8890
# 合并a和b所在的两个集合
8991
if find(a) != find(b):
9092
size[find(b)] += size[find(a)]
@@ -98,6 +100,7 @@ if find(a) != find(b):
98100
p = list(range(n))
99101
d = [0] * n
100102

103+
101104
# 返回x的祖宗节点
102105
def find(x):
103106
if p[x] != x:
@@ -106,6 +109,7 @@ def find(x):
106109
p[x] = t
107110
return p[x]
108111

112+
109113
# 合并a和b所在的两个集合
110114
p[find(a)] = find(b)
111115
d[find(a)] = distance
@@ -132,7 +136,10 @@ class Solution:
132136
return ans
133137

134138
m, n = len(grid), len(grid[0])
135-
return max([dfs(i, j) for i in range(m) for j in range(n) if grid[i][j] == 1], default=0)
139+
return max(
140+
[dfs(i, j) for i in range(m) for j in range(n) if grid[i][j] == 1],
141+
default=0,
142+
)
136143
```
137144

138145
并查集:
@@ -153,10 +160,18 @@ class Solution:
153160
if grid[i][j] == 1:
154161
for a, b in [[0, 1], [1, 0]]:
155162
x, y = i + a, j + b
156-
if 0 <= x < m and 0 <= y < n and grid[x][y] == 1 and find(i * n + j) != find(x * n + y):
163+
if (
164+
0 <= x < m
165+
and 0 <= y < n
166+
and grid[x][y] == 1
167+
and find(i * n + j) != find(x * n + y)
168+
):
157169
size[find(x * n + y)] += size[find(i * n + j)]
158170
p[find(i * n + j)] = find(x * n + y)
159-
return max([size[i * n + j] for i in range(m) for j in range(n) if grid[i][j] == 1], default=0)
171+
return max(
172+
[size[i * n + j] for i in range(m) for j in range(n) if grid[i][j] == 1],
173+
default=0,
174+
)
160175
```
161176

162177
### **Java**

lcof2/剑指 Offer II 106. 二分图/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ p[find(a)] = find(b)
9191
p = list(range(n))
9292
size = [1] * n
9393

94+
9495
# 返回x的祖宗节点
9596
def find(x):
9697
if p[x] != x:
9798
# 路径压缩
9899
p[x] = find(p[x])
99100
return p[x]
100101

102+
101103
# 合并a和b所在的两个集合
102104
if find(a) != find(b):
103105
size[find(b)] += size[find(a)]
@@ -111,6 +113,7 @@ if find(a) != find(b):
111113
p = list(range(n))
112114
d = [0] * n
113115

116+
114117
# 返回x的祖宗节点
115118
def find(x):
116119
if p[x] != x:
@@ -119,6 +122,7 @@ def find(x):
119122
p[x] = t
120123
return p[x]
121124

125+
122126
# 合并a和b所在的两个集合
123127
p[find(a)] = find(b)
124128
d[find(a)] = distance

0 commit comments

Comments
 (0)