Skip to content

Commit 2e834a7

Browse files
committed
style: format code and documents
1 parent 856a024 commit 2e834a7

File tree

573 files changed

+11955
-11698
lines changed

Some content is hidden

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

573 files changed

+11955
-11698
lines changed

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"useTabs": false,
44
"semi": true,
55
"singleQuote": true,
6-
"TrailingCooma": "all",
6+
"trailingComma": "all",
77
"bracketSpacing": true,
88
"jsxBracketSameLine": false,
99
"arrowParens": "avoid"

CODE_OF_CONDUCT.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ appearance, race, religion, or sexual identity and orientation.
1414
Examples of behavior that contributes to creating a positive environment
1515
include:
1616

17-
- Using welcoming and inclusive language
18-
- Being respectful of differing viewpoints and experiences
19-
- Gracefully accepting constructive criticism
20-
- Focusing on what is best for the community
21-
- Showing empathy towards other community members
17+
- Using welcoming and inclusive language
18+
- Being respectful of differing viewpoints and experiences
19+
- Gracefully accepting constructive criticism
20+
- Focusing on what is best for the community
21+
- Showing empathy towards other community members
2222

2323
Examples of unacceptable behavior by participants include:
2424

25-
- The use of sexualized language or imagery and unwelcome sexual attention or
25+
- The use of sexualized language or imagery and unwelcome sexual attention or
2626
advances
27-
- Trolling, insulting/derogatory comments, and personal or political attacks
28-
- Public or private harassment
29-
- Publishing others' private information, such as a physical or electronic
27+
- Trolling, insulting/derogatory comments, and personal or political attacks
28+
- Public or private harassment
29+
- Publishing others' private information, such as a physical or electronic
3030
address, without explicit permission
31-
- Other conduct which could reasonably be considered inappropriate in a
31+
- Other conduct which could reasonably be considered inappropriate in a
3232
professional setting
3333

3434
## Our Responsibilities

README.md

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

README_EN.md

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

basic/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
## 排序算法
44

5-
- [冒泡排序](./sorting/BubbleSort/README.md)
6-
- [插入排序](./sorting/InsertionSort/README.md)
7-
- [选择排序](./sorting/SelectionSort/README.md)
8-
- [归并排序](./sorting/MergeSort/README.md)
9-
- [快速排序](./sorting/QuickSort/README.md)
10-
- [堆排序](./sorting/HeapSort/README.md)
5+
- [冒泡排序](./sorting/BubbleSort/README.md)
6+
- [插入排序](./sorting/InsertionSort/README.md)
7+
- [选择排序](./sorting/SelectionSort/README.md)
8+
- [归并排序](./sorting/MergeSort/README.md)
9+
- [快速排序](./sorting/QuickSort/README.md)
10+
- [堆排序](./sorting/HeapSort/README.md)
1111

1212
## 查找算法
1313

14-
- [二分查找](./searching/BinarySearch/README.md)
14+
- [二分查找](./searching/BinarySearch/README.md)

basic/README_EN.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
## Sorting
44

5-
- [Bubble Sort](./sorting/BubbleSort/README.md)
6-
- [Insertion Sort](./sorting/InsertionSort/README.md)
7-
- [Selection Sort](./sorting/SelectionSort/README.md)
8-
- [Merge Sort](./sorting/MergeSort/README.md)
9-
- [Quick Sort](./sorting/QuickSort/README.md)
10-
- [Shell Sort](./sorting/ShellSort/README.md)
11-
- [Heap Sort](./sorting/HeapSort/README.md)
5+
- [Bubble Sort](./sorting/BubbleSort/README.md)
6+
- [Insertion Sort](./sorting/InsertionSort/README.md)
7+
- [Selection Sort](./sorting/SelectionSort/README.md)
8+
- [Merge Sort](./sorting/MergeSort/README.md)
9+
- [Quick Sort](./sorting/QuickSort/README.md)
10+
- [Shell Sort](./sorting/ShellSort/README.md)
11+
- [Heap Sort](./sorting/HeapSort/README.md)
1212

1313
## Searching
1414

15-
- [Binary Search](./searching/BinarySearch/README.md)
15+
- [Binary Search](./searching/BinarySearch/README.md)

basic/searching/BinarySearch/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ int search(int left, int right) {
5353

5454
## 例题
5555

56-
- [在排序数组中查找元素的第一个和最后一个位置](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md)
57-
- [x 的平方根](/solution/0000-0099/0069.Sqrt%28x%29/README.md)
58-
- [寻找峰值](/solution/0100-0199/0162.Find%20Peak%20Element/README.md)
59-
- [第一个错误的版本](/solution/0200-0299/0278.First%20Bad%20Version/README.md)
60-
- [不动点](/solution/1000-1099/1064.Fixed%20Point/README.md)
56+
- [在排序数组中查找元素的第一个和最后一个位置](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md)
57+
- [x 的平方根](/solution/0000-0099/0069.Sqrt%28x%29/README.md)
58+
- [寻找峰值](/solution/0100-0199/0162.Find%20Peak%20Element/README.md)
59+
- [第一个错误的版本](/solution/0200-0299/0278.First%20Bad%20Version/README.md)
60+
- [不动点](/solution/1000-1099/1064.Fixed%20Point/README.md)

basic/searching/BinarySearch/README_EN.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ int search(int left, int right) {
4040

4141
## Examples
4242

43-
- [Find First and Last Position of Element in Sorted Array](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md)
44-
- [Sqrt(x)](/solution/0000-0099/0069.Sqrt%28x%29/README_EN.md)
45-
- [Find Peak Element](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md)
46-
- [First Bad Version](/solution/0200-0299/0278.First%20Bad%20Version/README_EN.md)
47-
- [Fixed Point](/solution/1000-1099/1064.Fixed%20Point/README_EN.md)
43+
- [Find First and Last Position of Element in Sorted Array](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md)
44+
- [Sqrt(x)](/solution/0000-0099/0069.Sqrt%28x%29/README_EN.md)
45+
- [Find Peak Element](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md)
46+
- [First Bad Version](/solution/0200-0299/0278.First%20Bad%20Version/README_EN.md)
47+
- [Fixed Point](/solution/1000-1099/1064.Fixed%20Point/README_EN.md)

basic/sorting/HeapSort/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ for (int i = n / 2; i > 0; --i) {
5151

5252
**数据范围**
5353

54-
- 1 ≤ m ≤ n ≤ 10^5
55-
- 1 ≤ 数列中元素 ≤ 10^9
54+
- 1 ≤ m ≤ n ≤ 10^5
55+
- 1 ≤ 数列中元素 ≤ 10^9
5656

5757
**输入样例:**
5858

basic/sorting/InsertionSort/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
与冒泡排序对比:
1212

13-
- 在冒泡排序中,经过每一轮的排序处理后,数组后端的数是排好序的。
14-
- 在插入排序中,经过每一轮的排序处理后,数组前端的数是排好序的。
13+
- 在冒泡排序中,经过每一轮的排序处理后,数组后端的数是排好序的。
14+
- 在插入排序中,经过每一轮的排序处理后,数组前端的数是排好序的。
1515

1616
## 代码示例
1717

basic/sorting/MergeSort/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,17 @@ public class Main {
164164
### **JavaScript**
165165

166166
```js
167-
var buf = "";
167+
var buf = '';
168168

169-
process.stdin.on("readable", function () {
169+
process.stdin.on('readable', function () {
170170
var chunk = process.stdin.read();
171171
if (chunk) buf += chunk.toString();
172172
});
173173

174174
let getInputArgs = line => {
175175
return line
176-
.split(" ")
177-
.filter(s => s !== "")
176+
.split(' ')
177+
.filter(s => s !== '')
178178
.map(x => parseInt(x));
179179
};
180180

@@ -207,12 +207,12 @@ function mergeSort(nums, left, right) {
207207
}
208208
}
209209

210-
process.stdin.on("end", function () {
211-
buf.split("\n").forEach(function (line, lineIdx) {
210+
process.stdin.on('end', function () {
211+
buf.split('\n').forEach(function (line, lineIdx) {
212212
if (lineIdx % 2 === 1) {
213213
nums = getInputArgs(line);
214214
mergeSort(nums, 0, nums.length - 1);
215-
console.log(nums.join(" "));
215+
console.log(nums.join(' '));
216216
}
217217
});
218218
});

basic/sorting/QuickSort/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,17 @@ public class Main {
138138
### **JavaScript**
139139

140140
```js
141-
var buf = "";
141+
var buf = '';
142142

143-
process.stdin.on("readable", function () {
143+
process.stdin.on('readable', function () {
144144
var chunk = process.stdin.read();
145145
if (chunk) buf += chunk.toString();
146146
});
147147

148148
let getInputArgs = line => {
149149
return line
150-
.split(" ")
151-
.filter(s => s !== "")
150+
.split(' ')
151+
.filter(s => s !== '')
152152
.map(x => parseInt(x));
153153
};
154154

@@ -173,12 +173,12 @@ function quickSort(nums, left, right) {
173173
quickSort(nums, j + 1, right);
174174
}
175175

176-
process.stdin.on("end", function () {
177-
buf.split("\n").forEach(function (line, lineIdx) {
176+
process.stdin.on('end', function () {
177+
buf.split('\n').forEach(function (line, lineIdx) {
178178
if (lineIdx % 2 === 1) {
179179
nums = getInputArgs(line);
180180
quickSort(nums, 0, nums.length - 1);
181-
console.log(nums.join(" "));
181+
console.log(nums.join(' '));
182182
}
183183
});
184184
});

basic/sorting/SelectionSort/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public class Program
180180
}
181181
}
182182
public static void SelectionSortNums(int[] nums)
183-
{
183+
{
184184
for (int initial = 0; initial < nums.Length; initial++)
185185
{
186186
for (int second_sort = initial; second_sort < nums.Length; second_sort++)

basic/sorting/ShellSort/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
希尔排序,也被称为递减增量排序,是简单插入排序的一种改进版本。
44

5-
- 在插入排序中,如果待排序列中的某个元素,距离有序数列中待插入位置非常远,就需要比较很多次才可以到达插入位置,这是因为待插入元素局部非常无序,比如说`[2, 3, 4, 5, 6, 7, 8, 1, ...]`,我们要插入 1,就必须将 1 和前面的 2-8 每个值都比较一下,就是因为 1 附近非常无序,想象一下,如果待插入元素附近比较有序,那么在进行插入排序的时候就只需要比较非常少的几次就可以插入到正确位置。
6-
- 希尔排序就是先把整个序列排得相对比较有序,再进行插入排序的时候,需要比较的次数就会变得很少。
7-
- 插入排序的增量(间隔)为 1,希尔排序相当于将这个间隔从最大为数组长度的一半一直降到 1,这一点在程序中体现的很清楚。当间隔很大时,比较的次数也会很少,在进行了几次大间隔的插入排序后,序列已经部分有序,这样再进行小间隔的插入排序也自然会比较很少的次数。
8-
- 希尔排序就是将处在相同间隔的元素提取出来单独进行插入排序,然后逐步将间隔减小到 1 的过程。
5+
- 在插入排序中,如果待排序列中的某个元素,距离有序数列中待插入位置非常远,就需要比较很多次才可以到达插入位置,这是因为待插入元素局部非常无序,比如说`[2, 3, 4, 5, 6, 7, 8, 1, ...]`,我们要插入 1,就必须将 1 和前面的 2-8 每个值都比较一下,就是因为 1 附近非常无序,想象一下,如果待插入元素附近比较有序,那么在进行插入排序的时候就只需要比较非常少的几次就可以插入到正确位置。
6+
- 希尔排序就是先把整个序列排得相对比较有序,再进行插入排序的时候,需要比较的次数就会变得很少。
7+
- 插入排序的增量(间隔)为 1,希尔排序相当于将这个间隔从最大为数组长度的一半一直降到 1,这一点在程序中体现的很清楚。当间隔很大时,比较的次数也会很少,在进行了几次大间隔的插入排序后,序列已经部分有序,这样再进行小间隔的插入排序也自然会比较很少的次数。
8+
- 希尔排序就是将处在相同间隔的元素提取出来单独进行插入排序,然后逐步将间隔减小到 1 的过程。
99

1010
## 代码示例
1111

@@ -129,7 +129,7 @@ fn main() {
129129

130130
希尔排序的时间性能取决于所取“增量”序列的函数,这涉及到一些数学上尚未解决的难题。但是有人通过大量的实验,给出了较好的结果:当 n 较大时,比较和移动的次数约在 `n^1.25``(1.6n)^1.25` 之间。所以可以这样简单记忆:
131131

132-
- 当 n 较小时,希尔排序和插入排序相差不大,都为 n² 左右。
133-
- 当 n 很大时,时间增长幅度逐渐放缓,平均复杂度是 nlogn。
132+
- 当 n 较小时,希尔排序和插入排序相差不大,都为 n² 左右。
133+
- 当 n 很大时,时间增长幅度逐渐放缓,平均复杂度是 nlogn。
134134

135135
空间复杂度:O(1)。

basic/summary.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
- 基础算法通关
2-
- 排序算法
3-
- [冒泡排序](/basic/sorting/BubbleSort/README.md)
4-
- [插入排序](/basic/sorting/InsertionSort/README.md)
5-
- [选择排序](/basic/sorting/SelectionSort/README.md)
6-
- [归并排序](/basic/sorting/MergeSort/README.md)
7-
- [快速排序](/basic/sorting/QuickSort/README.md)
8-
- [堆排序](/basic/sorting/HeapSort/README.md)
9-
- 查找算法
10-
- [二分查找](/basic/searching/BinarySearch/README.md)
1+
- 基础算法通关
2+
- 排序算法
3+
- [冒泡排序](/basic/sorting/BubbleSort/README.md)
4+
- [插入排序](/basic/sorting/InsertionSort/README.md)
5+
- [选择排序](/basic/sorting/SelectionSort/README.md)
6+
- [归并排序](/basic/sorting/MergeSort/README.md)
7+
- [快速排序](/basic/sorting/QuickSort/README.md)
8+
- [堆排序](/basic/sorting/HeapSort/README.md)
9+
- 查找算法
10+
- [二分查找](/basic/searching/BinarySearch/README.md)

lcci/01.01.Is Unique/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Solution {
8181
var isUnique = function (astr) {
8282
let bitmap = 0;
8383
for (let i = 0; i < astr.length; ++i) {
84-
const pos = astr[i].charCodeAt() - "a".charCodeAt();
84+
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
8585
if ((bitmap & (1 << pos)) != 0) {
8686
return false;
8787
}

lcci/01.01.Is Unique/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Solution {
7878
var isUnique = function (astr) {
7979
let bitmap = 0;
8080
for (let i = 0; i < astr.length; ++i) {
81-
const pos = astr[i].charCodeAt() - "a".charCodeAt();
81+
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
8282
if ((bitmap & (1 << pos)) != 0) {
8383
return false;
8484
}

lcci/01.01.Is Unique/Solution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
var isUnique = function (astr) {
66
let bitmap = 0;
77
for (let i = 0; i < astr.length; ++i) {
8-
const pos = astr[i].charCodeAt() - "a".charCodeAt();
8+
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
99
if ((bitmap & (1 << pos)) != 0) {
1010
return false;
1111
}

lcci/01.05.One Away/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ second = &quot;pal&quot;
3636

3737
接着开始遍历两字符串。若两个指针 `i`, `j` 所指向的字符 `first[i]``second[j]` 不相同:
3838

39-
-`diff == 1`,则 `i++`
40-
-`diff == -1`,则 `j++`
41-
-`diff == 0`,则 `i++`, `j++`
39+
- `diff == 1`,则 `i++`
40+
- `diff == -1`,则 `j++`
41+
- `diff == 0`,则 `i++`, `j++`
4242

4343
同时编辑次数 `op` 减 1。
4444

lcci/01.06.Compress String/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ var compressString = function (S) {
9494
if (!S) return S;
9595
let p = 0,
9696
q = 1;
97-
let res = "";
97+
let res = '';
9898
while (q < S.length) {
9999
if (S[p] != S[q]) {
100100
res += S[p] + (q - p);

lcci/01.06.Compress String/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The compressed string is &quot;a1b2c2d1&quot;, which is longer than the original
3232

3333
<p><strong>Note:</strong></p>
3434

35-
- `0 <= S.length <= 50000`
35+
- `0 <= S.length <= 50000`
3636

3737
## Solutions
3838

@@ -92,7 +92,7 @@ var compressString = function (S) {
9292
if (!S) return S;
9393
let p = 0,
9494
q = 1;
95-
let res = "";
95+
let res = '';
9696
while (q < S.length) {
9797
if (S[p] != S[q]) {
9898
res += S[p] + (q - p);

lcci/01.06.Compress String/Solution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var compressString = function (S) {
66
if (!S) return S;
77
let p = 0,
88
q = 1;
9-
let res = "";
9+
let res = '';
1010
while (q < S.length) {
1111
if (S[p] != S[q]) {
1212
res += S[p] + (q - p);

lcci/02.07.Intersection of Two Linked Lists/README_EN.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040

4141
<p><b>Notes:</b></p>
4242

43-
- If the two linked lists have no intersection at all, return&nbsp;<code>null</code>.
44-
- The linked lists must retain their original structure after the function returns.
45-
- You may assume there are no cycles anywhere in the entire linked structure.
46-
- Your code should preferably run in O(n) time and use only O(1) memory.
43+
- If the two linked lists have no intersection at all, return&nbsp;<code>null</code>.
44+
- The linked lists must retain their original structure after the function returns.
45+
- You may assume there are no cycles anywhere in the entire linked structure.
46+
- Your code should preferably run in O(n) time and use only O(1) memory.
4747

4848
## Solutions
4949

lcci/03.04.Implement Queue using Stacks/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
<!-- 这里可写通用的实现逻辑 -->
1313

14-
- 每次压入元素时,放入第 1 个栈中;
15-
- 第 2 个栈不为空时,不能倒入元素;
16-
- 第 2 个栈为空时,必须将第 1 个栈的所有元素按顺序倒入第 2 个栈中。
14+
- 每次压入元素时,放入第 1 个栈中;
15+
- 第 2 个栈不为空时,不能倒入元素;
16+
- 第 2 个栈为空时,必须将第 1 个栈的所有元素按顺序倒入第 2 个栈中。
1717

1818
<!-- tabs:start -->
1919

lcci/04.05.Legal Binary Search Tree/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Solution {
8585

8686
### **Go**
8787

88-
- 非递归中序遍历
88+
- 非递归中序遍历
8989

9090
```go
9191
func isValidBST(root *TreeNode) bool {
@@ -110,7 +110,7 @@ func isValidBST(root *TreeNode) bool {
110110
}
111111
```
112112

113-
- 利用上界下界判定
113+
- 利用上界下界判定
114114

115115
```go
116116
func isValidBST(root *TreeNode) bool {

0 commit comments

Comments
 (0)