Skip to content

Commit 1f54d3e

Browse files
authored
style: format code and docs (doocs#645)
1 parent 6536d1a commit 1f54d3e

File tree

3,609 files changed

+14695
-23708
lines changed

Some content is hidden

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

3,609 files changed

+14695
-23708
lines changed

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ include:
2323
Examples of unacceptable behavior by participants include:
2424

2525
- The use of sexualized language or imagery and unwelcome sexual attention or
26-
advances
26+
advances
2727
- Trolling, insulting/derogatory comments, and personal or political attacks
2828
- Public or private harassment
2929
- Publishing others' private information, such as a physical or electronic
30-
address, without explicit permission
30+
address, without explicit permission
3131
- Other conduct which could reasonably be considered inappropriate in a
32-
professional setting
32+
professional setting
3333

3434
## Our Responsibilities
3535

basic/searching/BinarySearch/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ int search(int left, int right) {
4545
1. 写出循环条件:`while (left < right)`,注意是 `left < right`,而非 `left <= right`
4646
1. 循环体内,先无脑写出 `mid = (left + right) >> 1`
4747
1. 根据具体题目,实现 `check()` 函数(有时很简单的逻辑,可以不定义 `check`),想一下究竟要用 `right = mid`(模板 1) 还是 `left = mid`(模板 2);
48-
- 如果 `right = mid`,那么无脑写出 else 语句 `left = mid + 1`,并且不需要更改 mid 的计算,即保持 `mid = (left + right) >> 1`
49-
- 如果 `left = mid`,那么无脑写出 else 语句 `right = mid - 1`,并且在 mid 计算时补充 +1,即 `mid = (left + right + 1) >> 1`
48+
- 如果 `right = mid`,那么无脑写出 else 语句 `left = mid + 1`,并且不需要更改 mid 的计算,即保持 `mid = (left + right) >> 1`
49+
- 如果 `left = mid`,那么无脑写出 else 语句 `right = mid - 1`,并且在 mid 计算时补充 +1,即 `mid = (left + right + 1) >> 1`
5050
1. 循环结束时,left 与 right 相等。
5151

5252
注意,这两个模板的优点是始终保持答案位于二分区间内,二分结束条件对应的值恰好在答案所处的位置。 对于可能无解的情况,只要判断二分结束后的 left 或者 right 是否满足题意即可。

basic/sorting/BubbleSort/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class BubbleSort {
4141
}
4242
}
4343
```
44+
4445
### **JavaScript**
4546

4647
```js
@@ -55,12 +56,12 @@ function bubbleSort(inputArr) {
5556
hasChange = true;
5657
}
5758
}
58-
59+
5960
if (!hasChange) {
6061
break;
6162
}
6263
}
63-
64+
6465
return inputArr;
6566
}
6667

basic/sorting/InsertionSort/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public class InsertionSort {
4141
}
4242
}
4343
```
44+
4445
### **JavaScript**
46+
4547
```js
4648
function insertionSort(inputArr) {
4749
let len = inputArr.length;
@@ -54,11 +56,11 @@ function insertionSort(inputArr) {
5456
}
5557
inputArr[j + 1] = temp;
5658
}
57-
return (inputArr);
59+
return inputArr;
5860
}
5961

6062
let arr = [6, 3, 2, 1, 5];
61-
console.log(insertionSort(arr))
63+
console.log(insertionSort(arr));
6264
```
6365

6466
### **Go**

basic/sorting/MergeSort/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,19 @@ 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 => {
175-
return line.split(' ').filter(s => s !== '').map(x => parseInt(x));
176-
}
175+
return line
176+
.split(" ")
177+
.filter(s => s !== "")
178+
.map(x => parseInt(x));
179+
};
177180

178181
function mergeSort(nums, left, right) {
179182
if (left >= right) {
@@ -204,16 +207,13 @@ function mergeSort(nums, left, right) {
204207
}
205208
}
206209

207-
208-
209-
process.stdin.on('end', function () {
210-
buf.split('\n').forEach(function (line, lineIdx) {
210+
process.stdin.on("end", function () {
211+
buf.split("\n").forEach(function (line, lineIdx) {
211212
if (lineIdx % 2 === 1) {
212213
nums = getInputArgs(line);
213214
mergeSort(nums, 0, nums.length - 1);
214-
console.log(nums.join(' '));
215+
console.log(nums.join(" "));
215216
}
216-
217217
});
218218
});
219219
```

basic/sorting/QuickSort/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void quickSort(int[] nums, int left, int right) {
6060
1 2 3 4 5
6161
```
6262

63-
6463
## 代码实现
6564

6665
<!-- tabs:start -->
@@ -139,16 +138,19 @@ public class Main {
139138
### **JavaScript**
140139

141140
```js
142-
var buf = '';
141+
var buf = "";
143142

144-
process.stdin.on('readable', function () {
143+
process.stdin.on("readable", function () {
145144
var chunk = process.stdin.read();
146145
if (chunk) buf += chunk.toString();
147146
});
148147

149148
let getInputArgs = line => {
150-
return line.split(' ').filter(s => s !== '').map(x => parseInt(x));
151-
}
149+
return line
150+
.split(" ")
151+
.filter(s => s !== "")
152+
.map(x => parseInt(x));
153+
};
152154

153155
function quickSort(nums, left, right) {
154156
if (left >= right) {
@@ -171,16 +173,13 @@ function quickSort(nums, left, right) {
171173
quickSort(nums, j + 1, right);
172174
}
173175

174-
175-
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
}
183-
184183
});
185184
});
186185
```
@@ -369,4 +368,5 @@ int main( void )
369368
return 0;
370369
}
371370
```
371+
372372
<!-- tabs:end -->

basic/sorting/SelectionSort/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ function selectionSort(inputArr) {
4949
let j = i;
5050
let min = j;
5151
while (j <= len - 1) {
52-
if (inputArr[j] < inputArr[min])
53-
min = j;
52+
if (inputArr[j] < inputArr[min]) min = j;
5453
j++;
5554
}
5655
let temp = inputArr[i];
@@ -61,7 +60,7 @@ function selectionSort(inputArr) {
6160
}
6261

6362
let arr = [6, 3, 2, 1, 5];
64-
console.log(selectionSort(arr))
63+
console.log(selectionSort(arr));
6564
```
6665

6766
### **Go**

basic/summary.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
- 基础算法通关
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)
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ class Solution {
7878
* @param {string} astr
7979
* @return {boolean}
8080
*/
81-
var isUnique = function(astr) {
81+
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
}
88-
bitmap |= (1 << pos);
88+
bitmap |= 1 << pos;
8989
}
9090
return true;
9191
};

lcci/01.01.Is Unique/README_EN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ class Solution {
7575
* @param {string} astr
7676
* @return {boolean}
7777
*/
78-
var isUnique = function(astr) {
78+
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
}
85-
bitmap |= (1 << pos);
85+
bitmap |= 1 << pos;
8686
}
8787
return true;
8888
};

0 commit comments

Comments
 (0)