Skip to content

Commit 23496d5

Browse files
committed
docs: update code
1 parent 1d5bedd commit 23496d5

File tree

20 files changed

+52
-52
lines changed

20 files changed

+52
-52
lines changed

lcci/03.02.Min Stack/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ minStack.getMin(); --&gt; return -2.</pre>
3434

3535
```python
3636
class MinStack:
37-
3837
def __init__(self):
3938
self.stk1 = []
4039
self.stk2 = [inf]

lcci/03.03.Stack of Plates/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
```python
4040
class StackOfPlates:
41-
4241
def __init__(self, cap: int):
4342
self.cap = cap
4443
self.stk = []

lcci/03.03.Stack of Plates/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
```python
4747
class StackOfPlates:
48-
4948
def __init__(self, cap: int):
5049
self.cap = cap
5150
self.stk = []

lcci/04.01.Route Between Nodes/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class Solution:
6565

6666
```python
6767
class Solution:
68-
def findWhetherExistsPath(self, n: int, graph: List[List[int]], start: int, target: int) -> bool:
68+
def findWhetherExistsPath(
69+
self, n: int, graph: List[List[int]], start: int, target: int
70+
) -> bool:
6971
g = defaultdict(list)
7072
for u, v in graph:
7173
g[u].append(v)

lcci/04.01.Route Between Nodes/README_EN.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class Solution:
6666

6767
```python
6868
class Solution:
69-
def findWhetherExistsPath(self, n: int, graph: List[List[int]], start: int, target: int) -> bool:
69+
def findWhetherExistsPath(
70+
self, n: int, graph: List[List[int]], start: int, target: int
71+
) -> bool:
7072
g = defaultdict(list)
7173
for u, v in graph:
7274
g[u].append(v)

lcci/04.02.Minimum Height Tree/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# self.left = None
3232
# self.right = None
3333

34+
3435
class Solution:
3536
def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
3637
def dfs(l, r):

lcci/04.02.Minimum Height Tree/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ One possible answer is: [0,-3,9,-10,null,5],which represents the following tre
4444
# self.left = None
4545
# self.right = None
4646

47+
4748
class Solution:
4849
def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
4950
def dfs(l, r):

lcci/04.03.List of Depth/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# self.left = None
4545
# self.right = None
4646

47+
4748
# Definition for singly-linked list.
4849
# class ListNode:
4950
# def __init__(self, x):

lcci/04.03.List of Depth/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Level order traversal.
5252
# self.left = None
5353
# self.right = None
5454

55+
5556
# Definition for singly-linked list.
5657
# class ListNode:
5758
# def __init__(self, x):

lcci/05.01.Insert Into Bits/README_EN.md

+1-19
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,21 @@
55
## Description
66

77
<p>You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to insert M into N such that M starts at bit j and ends at bit i. You can assume that the bits j through i have enough space to fit all of M. That is, if M = 10011, you can assume that there are at least 5 bits between j and i. You would not, for example, have j = 3 and i = 2, because M could not fully fit between bit 3 and bit 2.</p>
8-
98
<p><strong>Example1:</strong></p>
10-
119
<pre>
1210

13-
14-
1511
<strong> Input</strong>: N = 10000000000, M = 10011, i = 2, j = 6
1612

17-
18-
1913
<strong> Output</strong>: N = 10001001100
2014

21-
22-
2315
</pre>
24-
2516
<p><strong>Example2:</strong></p>
26-
2717
<pre>
2818

29-
30-
31-
<strong> Input</strong>: N = 0, M = 11111, i = 0, j = 4
32-
33-
19+
<strong> Input</strong>: N = 0, M = 11111, i = 0, j = 4
3420

3521
<strong> Output</strong>: N = 11111
3622

37-
38-
3923
</pre>
4024

4125
## Solutions
@@ -46,7 +30,6 @@
4630

4731
```python
4832

49-
5033
```
5134

5235
### **Java**
@@ -66,7 +49,6 @@ class Solution {
6649

6750
```
6851
69-
7052
```
7153

7254
<!-- tabs:end -->

lcci/17.05.Find Longest Subarray/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Solution:
6767
k = j + 1
6868
else:
6969
vis[s] = i
70-
return array[k: k + mx]
70+
return array[k : k + mx]
7171
```
7272

7373
### **Java**

lcci/17.05.Find Longest Subarray/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Solution:
5757
k = j + 1
5858
else:
5959
vis[s] = i
60-
return array[k: k + mx]
60+
return array[k : k + mx]
6161
```
6262

6363
### **Java**

lcci/17.20.Continuous Median/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ findMedian() -&gt; 2
5555

5656
```python
5757
class MedianFinder:
58-
5958
def __init__(self):
6059
"""
6160
initialize your data structure here.

lcci/17.20.Continuous Median/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ findMedian() -&gt; 2
4545

4646
```python
4747
class MedianFinder:
48-
4948
def __init__(self):
5049
"""
5150
initialize your data structure here.

lcci/17.23.Max Black Square/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ class Solution:
8989
for k in range(n, 0, -1):
9090
for i in range(n - k + 1):
9191
for j in range(n - k + 1):
92-
if down[i][j] >= k and right[i][j] >= k and right[i + k - 1][j] >= k and down[i][j + k - 1] >= k:
92+
if (
93+
down[i][j] >= k
94+
and right[i][j] >= k
95+
and right[i + k - 1][j] >= k
96+
and down[i][j + k - 1] >= k
97+
):
9398
return [i, j, k]
9499
return []
95100
```

lcci/17.23.Max Black Square/README_EN.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ class Solution:
6969
for k in range(n, 0, -1):
7070
for i in range(n - k + 1):
7171
for j in range(n - k + 1):
72-
if down[i][j] >= k and right[i][j] >= k and right[i + k - 1][j] >= k and down[i][j + k - 1] >= k:
72+
if (
73+
down[i][j] >= k
74+
and right[i][j] >= k
75+
and right[i + k - 1][j] >= k
76+
and down[i][j + k - 1] >= k
77+
):
7378
return [i, j, k]
7479
return []
7580
```

run_format.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,31 @@
66

77
def prettier_format():
88
"""Format code with prettier"""
9-
for suffix in ['md', 'js', 'ts']:
10-
command = f'npx prettier --write "**/*.{suffix}"'
11-
os.system(command)
12-
13-
# format php code
9+
# before prettier, add `<?php` to php files
1410
for root, _, files in os.walk(path):
1511
for name in files:
1612
if name.endswith('.php'):
17-
p1 = root + '/' + name
18-
with open(p1, 'r', encoding='utf-8') as f:
13+
p = root + '/' + name
14+
with open(p, 'r', encoding='utf-8') as f:
1915
content = f.read()
2016
content = '<?php\n' + content
21-
with open(p1, 'w', encoding='utf-8') as f:
17+
with open(p, 'w', encoding='utf-8') as f:
2218
f.write(content)
23-
command = 'npx prettier --write "**/*.php"'
24-
os.system(command)
19+
20+
# start formatting with prettier
21+
for suffix in ['md', 'js', 'ts', 'php']:
22+
command = f'npx prettier --write "**/*.{suffix}"'
23+
os.system(command)
24+
25+
# after prettier, remove `<?php` from php files
2526
for root, _, files in os.walk(path):
2627
for name in files:
2728
if name.endswith('.php'):
28-
p1 = root + '/' + name
29-
with open(p1, 'r', encoding='utf-8') as f:
29+
p = root + '/' + name
30+
with open(p, 'r', encoding='utf-8') as f:
3031
content = f.read()
3132
content = content.replace('<?php\n', '')
32-
with open(p1, 'w', encoding='utf-8') as f:
33+
with open(p, 'w', encoding='utf-8') as f:
3334
f.write(content)
3435

3536

@@ -48,11 +49,11 @@ def clang_format():
4849
for root, _, files in os.walk(path):
4950
for name in files:
5051
if name.endswith('.md'):
51-
p1 = root + '/' + name
52-
with open(p1, 'r', encoding='utf-8') as f:
52+
p = root + '/' + name
53+
with open(p, 'r', encoding='utf-8') as f:
5354
content = f.read()
5455
x = content
55-
print(p1)
56+
print(p)
5657
for suf in suffix:
5758
res = re.findall(f'```{suf}\n(.*?)```', content, re.S)
5859
if not res:
@@ -66,7 +67,7 @@ def clang_format():
6667
with open(p2, 'r', encoding='utf-8') as f:
6768
content = f.read()
6869
content = x.replace(v, content)
69-
with open(p1, 'w', encoding='utf-8') as f:
70+
with open(p, 'w', encoding='utf-8') as f:
7071
f.write(content)
7172
os.remove(p2)
7273

@@ -108,6 +109,6 @@ def git_add():
108109

109110
if __name__ == '__main__':
110111
prettier_format()
111-
black_format()
112+
# black_format()
112113
# clang_format()
113114
git_add()

solution/0000-0099/0022.Generate Parentheses/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838

3939
**方法一:DFS + 剪枝**
4040

41-
题目中 $n$ 的范围为 $[1, 8]$,因此我们直接通过“暴力搜索 + 剪枝”的方式快速解决本题
41+
题目中 $n$ 的范围为 $[1, 8]$,因此我们直接通过“暴力搜索 + 剪枝”的方式通过本题
4242

43-
我们设计函数 `dfs(l, r, t)`,其中 $l$ 和 $r$ 分别表示左括号和右括号的数量,而 $t$ 表示当前的括号序列。那么我们可以得到如下的递归结构:
43+
我们设计一个函数 $dfs(l, r, t)$,其中 $l$ 和 $r$ 分别表示左括号和右括号的数量,而 $t$ 表示当前的括号序列。那么我们可以得到如下的递归结构:
4444

4545
- 如果 $l \gt n$ 或者 $r \gt n$ 或者 $l \lt r$,那么当前括号组合 $t$ 不合法,直接返回;
4646
- 如果 $l = n$ 且 $r = n$,那么当前括号组合 $t$ 合法,将其加入答案数组 `ans` 中,直接返回;

solution/1700-1799/1732.Find the Highest Altitude/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ class Solution {
191191
$max = 0;
192192
for ($i = 0; $i < count($gain); $i++) {
193193
$tmp += $gain[$i];
194-
if ($tmp > $max) $max = $tmp;
194+
if ($tmp > $max) {
195+
$max = $tmp;
196+
}
195197
}
196198
return $max;
197199
}

solution/1700-1799/1732.Find the Highest Altitude/README_EN.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ class Solution {
161161
$max = 0;
162162
for ($i = 0; $i < count($gain); $i++) {
163163
$tmp += $gain[$i];
164-
if ($tmp > $max) $max = $tmp;
164+
if ($tmp > $max) {
165+
$max = $tmp;
166+
}
165167
}
166168
return $max;
167169
}

0 commit comments

Comments
 (0)