Skip to content

Commit eaf14ba

Browse files
committed
style: format code and documents
1 parent 6d7cee7 commit eaf14ba

File tree

171 files changed

+20871
-20547
lines changed

Some content is hidden

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

171 files changed

+20871
-20547
lines changed

README.md

+284-284
Large diffs are not rendered by default.

README_EN.md

+268-268
Large diffs are not rendered by default.

lcci/10.01.Sorted Merge/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ impl Solution {
107107
}
108108
```
109109

110-
111110
### **...**
112111

113112
```

lcci/10.02.Group Anagrams/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ impl Solution {
149149
}
150150
```
151151

152-
153152
### **...**
154153

155154
```

lcci/17.04.Missing Number/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
- 排序 `nums`,检查 `nums[i] == i`,返回条件不成立的 `i`
3131
- 若全部符合条件,则返回 `nums.length`
3232
2. 数学
33-
- 遍历 `nums`,统计总和,并记录其中的最大值。
34-
- 若最大值与 `nums.length` 一致,使用高斯算法(`(n + 1) * n / 2`)计算总和,与遍历总和相减,得到结果。
35-
- 不一致,则缺失的就是 `nums.length`
33+
- 遍历 `nums`,统计总和,并记录其中的最大值。
34+
- 若最大值与 `nums.length` 一致,使用高斯算法(`(n + 1) * n / 2`)计算总和,与遍历总和相减,得到结果。
35+
- 不一致,则缺失的就是 `nums.length`
3636
3. 位运算
37-
- 利用异或的特性,`res = res ^ x ^ x`。对同一个值异或两次,结果等于它本身。最后异或的结果,就是只出现一次的数字,即数组中缺失的整数。
37+
- 利用异或的特性,`res = res ^ x ^ x`。对同一个值异或两次,结果等于它本身。最后异或的结果,就是只出现一次的数字,即数组中缺失的整数。
3838

3939
<!-- tabs:start -->
4040

lcci/17.11.Find Closest/Solution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Solution:
22
def findClosest(self, words: List[str], word1: str, word2: str) -> int:
3-
idx1, idx2, ans = 10**5, -10**5, 10**5
3+
idx1, idx2, ans = 10**5, -(10**5), 10**5
44
for i, word in enumerate(words):
55
if word == word1:
66
idx1 = i

lcci/17.17.Multi Search/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private:
159159

160160
public:
161161
Trie() : children(26), idx(-1) {}
162-
162+
163163
void insert(string word, int i) {
164164
Trie* node = this;
165165
for (char c : word)
@@ -170,7 +170,7 @@ public:
170170
}
171171
node->idx = i;
172172
}
173-
173+
174174
vector<int> search(string word) {
175175
Trie* node = this;
176176
vector<int> res;

lcci/17.17.Multi Search/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private:
156156

157157
public:
158158
Trie() : children(26), idx(-1) {}
159-
159+
160160
void insert(string word, int i) {
161161
Trie* node = this;
162162
for (char c : word)
@@ -167,7 +167,7 @@ public:
167167
}
168168
node->idx = i;
169169
}
170-
170+
171171
vector<int> search(string word) {
172172
Trie* node = this;
173173
vector<int> res;

lcof/面试题57. 和为s的两个数字/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
- 存在,即 `return` 返回。
3737
- 不存在,记录元素,继续遍历。
3838

39-
*复杂度*
39+
_复杂度_
4040

41-
- 时间 ***O(N)***
42-
- 空间 ***O(N)***
41+
- 时间 **_O(N)_**
42+
- 空间 **_O(N)_**
4343

4444
**双指针**
4545

@@ -52,10 +52,10 @@
5252

5353
> 因为数组是有序的,指针变动对值的影响可预测。
5454
55-
*复杂度*
55+
_复杂度_
5656

57-
- 时间 ***O(N)***
58-
- 空间 ***O(1)***
57+
- 时间 **_O(N)_**
58+
- 空间 **_O(1)_**
5959

6060
```txt
6161
TWO-SUM(A,t)

lcof2/剑指 Offer II 034. 外星语言是否排序/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ function isAlienSorted(words: string[], order: string): boolean {
122122
function compare(str1: string, str2: string): boolean {
123123
const n = Math.min(str1.length, str2.length);
124124
for (let i = 0; i < n; i++) {
125-
let k1 = str1[i], k2 = str2[i];
125+
let k1 = str1[i],
126+
k2 = str2[i];
126127
if (k1 != k2) return charMap.get(k1) < charMap.get(k2);
127128
}
128129
return n == str1.length;
@@ -131,7 +132,7 @@ function isAlienSorted(words: string[], order: string): boolean {
131132
if (!compare(words[i - 1], words[i])) return false;
132133
}
133134
return true;
134-
};
135+
}
135136
```
136137

137138
### **C++**

lcp/LCP 05. 发 LeetCoin/Solution.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def pushdown(self, node):
6565

6666

6767
class Solution:
68-
def bonus(self, n: int, leadership: List[List[int]], operations: List[List[int]]) -> List[int]:
68+
def bonus(
69+
self, n: int, leadership: List[List[int]], operations: List[List[int]]
70+
) -> List[int]:
6971
def dfs(u):
7072
nonlocal idx
7173
begin[u] = idx

solution/0000-0099/0015.3Sum/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353
1.`nums` 进行排序。
5454
2. 遍历数组,并以当前遍历位置作为分割线,在右侧数组当中(不包括分割元素在内),寻找两个可以组成 `0 - nums[i]` 的值,将该题转换为**两数之和**
5555

56-
> 更贴切的说,与 [剑指 Offer 57. 和为s的两个数字](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/) 目标一致
56+
> 更贴切的说,与 [剑指 Offer 57. 和为 s 的两个数字](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/) 目标一致
5757
5858
**优化:**
5959

60-
-`nums[i] > 0` 时,其后续的数值都比 `nums[i]` 大,那么就不可能存在两个数值一起组合为 0,可以提前结束遍历。
61-
- 若当前遍历数值与上一个数值一致(`nums[i] == nums[i - 1]`),可直接跳过(去重复)。
62-
- 相比两数之和,与其不同的是:**目标数组是有序的**。可使用**二分查找****头尾指针**快速搜索目标。
60+
- `nums[i] > 0` 时,其后续的数值都比 `nums[i]` 大,那么就不可能存在两个数值一起组合为 0,可以提前结束遍历。
61+
- 若当前遍历数值与上一个数值一致(`nums[i] == nums[i - 1]`),可直接跳过(去重复)。
62+
- 相比两数之和,与其不同的是:**目标数组是有序的**。可使用**二分查找****头尾指针**快速搜索目标。
6363

6464
**重复问题:**
6565

solution/0000-0099/0015.3Sum/README_EN.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public class ThreeSumComparer: IEqualityComparer<IList<int>>
214214
{
215215
return left[0] == right[0] && left[1] == right[1] && left[2] == right[2];
216216
}
217-
217+
218218
public int GetHashCode(IList<int> obj)
219219
{
220220
return (obj[0] ^ obj[1] ^ obj[2]).GetHashCode();
@@ -225,7 +225,7 @@ public class Solution {
225225
public IList<IList<int>> ThreeSum(int[] nums) {
226226
Array.Sort(nums);
227227
var results = new HashSet<IList<int>>(new ThreeSumComparer());
228-
228+
229229
var cIndex = Array.BinarySearch(nums, 0);
230230
if (cIndex < 0) cIndex = ~cIndex;
231231
while (cIndex < nums.Length)
@@ -253,7 +253,7 @@ public class Solution {
253253
step /= 2;
254254
}
255255
}
256-
256+
257257
if (nums[aIndex] + nums[bIndex] + c > 0)
258258
{
259259
var step = 1;
@@ -272,7 +272,7 @@ public class Solution {
272272
step /= 2;
273273
}
274274
}
275-
275+
276276
if (nums[aIndex] + nums[bIndex] + c == 0)
277277
{
278278
var list = new List<int> { nums[aIndex], nums[bIndex], c };
@@ -291,7 +291,7 @@ public class Solution {
291291
}
292292
++cIndex;
293293
}
294-
294+
295295
return results.ToList();
296296
}
297297
}

solution/0000-0099/0048.Rotate Image/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public:
124124
* @return {void} Do not return anything, modify matrix in-place instead.
125125
*/
126126
var rotate = function (matrix) {
127-
const n = matrix.length
127+
const n = matrix.length;
128128
for (let i = 0; i < n; i++) {
129129
for (let j = 0; j <= i; j++) {
130130
[matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]];

solution/0000-0099/0075.Sort Colors/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl Solution {
201201
if n == 0 {
202202
nums.swap(i, l);
203203
l += 1;
204-
}
204+
}
205205
i += 1;
206206
}
207207
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
class Solution:
2-
def minWindow(self, s: str, t: str) -> str:
3-
ans = ''
4-
m, n = len(s), len(t)
5-
if m < n:
6-
return ans
7-
need = Counter(t)
8-
window = Counter()
9-
i, cnt, mi = 0, 0, float('inf')
10-
for j, c in enumerate(s):
11-
window[c] += 1
12-
if need[c] >= window[c]:
13-
cnt += 1
14-
while cnt == n:
15-
if j - i + 1 < mi:
16-
mi = j - i + 1
17-
ans = s[i: j + 1]
18-
c = s[i]
19-
if need[c] >= window[c]:
20-
cnt -= 1
21-
window[c] -= 1
22-
i += 1
23-
return ans
1+
class Solution:
2+
def minWindow(self, s: str, t: str) -> str:
3+
ans = ''
4+
m, n = len(s), len(t)
5+
if m < n:
6+
return ans
7+
need = Counter(t)
8+
window = Counter()
9+
i, cnt, mi = 0, 0, float('inf')
10+
for j, c in enumerate(s):
11+
window[c] += 1
12+
if need[c] >= window[c]:
13+
cnt += 1
14+
while cnt == n:
15+
if j - i + 1 < mi:
16+
mi = j - i + 1
17+
ans = s[i : j + 1]
18+
c = s[i]
19+
if need[c] >= window[c]:
20+
cnt -= 1
21+
window[c] -= 1
22+
i += 1
23+
return ans

solution/0100-0199/0146.Lru Cache/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class LRUCache {
205205
head.next = tail;
206206
tail.prev = head;
207207
}
208-
208+
209209
public int get(int key) {
210210
if (!cache.containsKey(key)) {
211211
return -1;
@@ -214,7 +214,7 @@ class LRUCache {
214214
moveToHead(node);
215215
return node.val;
216216
}
217-
217+
218218
public void put(int key, int value) {
219219
if (cache.containsKey(key)) {
220220
Node node = cache.get(key);
@@ -486,14 +486,14 @@ public:
486486
head->next = tail;
487487
tail->prev = head;
488488
}
489-
489+
490490
int get(int key) {
491491
if (!cache.count(key)) return -1;
492492
Node* node = cache[key];
493493
moveToHead(node);
494494
return node->v;
495495
}
496-
496+
497497
void put(int key, int value) {
498498
if (cache.count(key))
499499
{

solution/0100-0199/0146.Lru Cache/README_EN.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class LRUCache {
154154
head.next = tail;
155155
tail.prev = head;
156156
}
157-
157+
158158
public int get(int key) {
159159
if (!cache.containsKey(key)) {
160160
return -1;
@@ -163,7 +163,7 @@ class LRUCache {
163163
moveToHead(node);
164164
return node.val;
165165
}
166-
166+
167167
public void put(int key, int value) {
168168
if (cache.containsKey(key)) {
169169
Node node = cache.get(key);
@@ -435,14 +435,14 @@ public:
435435
head->next = tail;
436436
tail->prev = head;
437437
}
438-
438+
439439
int get(int key) {
440440
if (!cache.count(key)) return -1;
441441
Node* node = cache[key];
442442
moveToHead(node);
443443
return node->v;
444444
}
445-
445+
446446
void put(int key, int value) {
447447
if (cache.count(key))
448448
{

0 commit comments

Comments
 (0)