Skip to content

Commit

Permalink
style: format code and docs (doocs#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme authored Dec 24, 2021
1 parent 6536d1a commit 1f54d3e
Show file tree
Hide file tree
Showing 3,609 changed files with 14,695 additions and 23,708 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
6 changes: 3 additions & 3 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ include:
Examples of unacceptable behavior by participants include:

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

## Our Responsibilities

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

注意,这两个模板的优点是始终保持答案位于二分区间内,二分结束条件对应的值恰好在答案所处的位置。 对于可能无解的情况,只要判断二分结束后的 left 或者 right 是否满足题意即可。
Expand Down
5 changes: 3 additions & 2 deletions basic/sorting/BubbleSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class BubbleSort {
}
}
```

### **JavaScript**

```js
Expand All @@ -55,12 +56,12 @@ function bubbleSort(inputArr) {
hasChange = true;
}
}

if (!hasChange) {
break;
}
}

return inputArr;
}

Expand Down
6 changes: 4 additions & 2 deletions basic/sorting/InsertionSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public class InsertionSort {
}
}
```

### **JavaScript**

```js
function insertionSort(inputArr) {
let len = inputArr.length;
Expand All @@ -54,11 +56,11 @@ function insertionSort(inputArr) {
}
inputArr[j + 1] = temp;
}
return (inputArr);
return inputArr;
}

let arr = [6, 3, 2, 1, 5];
console.log(insertionSort(arr))
console.log(insertionSort(arr));
```

### **Go**
Expand Down
20 changes: 10 additions & 10 deletions basic/sorting/MergeSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,19 @@ public class Main {
### **JavaScript**

```js
var buf = '';
var buf = "";

process.stdin.on('readable', function () {
process.stdin.on("readable", function () {
var chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});

let getInputArgs = line => {
return line.split(' ').filter(s => s !== '').map(x => parseInt(x));
}
return line
.split(" ")
.filter(s => s !== "")
.map(x => parseInt(x));
};

function mergeSort(nums, left, right) {
if (left >= right) {
Expand Down Expand Up @@ -204,16 +207,13 @@ function mergeSort(nums, left, right) {
}
}



process.stdin.on('end', function () {
buf.split('\n').forEach(function (line, lineIdx) {
process.stdin.on("end", function () {
buf.split("\n").forEach(function (line, lineIdx) {
if (lineIdx % 2 === 1) {
nums = getInputArgs(line);
mergeSort(nums, 0, nums.length - 1);
console.log(nums.join(' '));
console.log(nums.join(" "));
}

});
});
```
Expand Down
22 changes: 11 additions & 11 deletions basic/sorting/QuickSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ void quickSort(int[] nums, int left, int right) {
1 2 3 4 5
```


## 代码实现

<!-- tabs:start -->
Expand Down Expand Up @@ -139,16 +138,19 @@ public class Main {
### **JavaScript**

```js
var buf = '';
var buf = "";

process.stdin.on('readable', function () {
process.stdin.on("readable", function () {
var chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});

let getInputArgs = line => {
return line.split(' ').filter(s => s !== '').map(x => parseInt(x));
}
return line
.split(" ")
.filter(s => s !== "")
.map(x => parseInt(x));
};

function quickSort(nums, left, right) {
if (left >= right) {
Expand All @@ -171,16 +173,13 @@ function quickSort(nums, left, right) {
quickSort(nums, j + 1, right);
}



process.stdin.on('end', function () {
buf.split('\n').forEach(function (line, lineIdx) {
process.stdin.on("end", function () {
buf.split("\n").forEach(function (line, lineIdx) {
if (lineIdx % 2 === 1) {
nums = getInputArgs(line);
quickSort(nums, 0, nums.length - 1);
console.log(nums.join(' '));
console.log(nums.join(" "));
}

});
});
```
Expand Down Expand Up @@ -369,4 +368,5 @@ int main( void )
return 0;
}
```
<!-- tabs:end -->
5 changes: 2 additions & 3 deletions basic/sorting/SelectionSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ function selectionSort(inputArr) {
let j = i;
let min = j;
while (j <= len - 1) {
if (inputArr[j] < inputArr[min])
min = j;
if (inputArr[j] < inputArr[min]) min = j;
j++;
}
let temp = inputArr[i];
Expand All @@ -61,7 +60,7 @@ function selectionSort(inputArr) {
}

let arr = [6, 3, 2, 1, 5];
console.log(selectionSort(arr))
console.log(selectionSort(arr));
```

### **Go**
Expand Down
18 changes: 9 additions & 9 deletions basic/summary.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
- 基础算法通关
- 排序算法
- [冒泡排序](/basic/sorting/BubbleSort/README.md)
- [插入排序](/basic/sorting/InsertionSort/README.md)
- [选择排序](/basic/sorting/SelectionSort/README.md)
- [归并排序](/basic/sorting/MergeSort/README.md)
- [快速排序](/basic/sorting/QuickSort/README.md)
- [堆排序](/basic/sorting/HeapSort/README.md)
- 查找算法
- [二分查找](/basic/searching/BinarySearch/README.md)
- 排序算法
- [冒泡排序](/basic/sorting/BubbleSort/README.md)
- [插入排序](/basic/sorting/InsertionSort/README.md)
- [选择排序](/basic/sorting/SelectionSort/README.md)
- [归并排序](/basic/sorting/MergeSort/README.md)
- [快速排序](/basic/sorting/QuickSort/README.md)
- [堆排序](/basic/sorting/HeapSort/README.md)
- 查找算法
- [二分查找](/basic/searching/BinarySearch/README.md)
6 changes: 3 additions & 3 deletions lcci/01.01.Is Unique/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ class Solution {
* @param {string} astr
* @return {boolean}
*/
var isUnique = function(astr) {
var isUnique = function (astr) {
let bitmap = 0;
for (let i = 0; i < astr.length; ++i) {
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
const pos = astr[i].charCodeAt() - "a".charCodeAt();
if ((bitmap & (1 << pos)) != 0) {
return false;
}
bitmap |= (1 << pos);
bitmap |= 1 << pos;
}
return true;
};
Expand Down
6 changes: 3 additions & 3 deletions lcci/01.01.Is Unique/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ class Solution {
* @param {string} astr
* @return {boolean}
*/
var isUnique = function(astr) {
var isUnique = function (astr) {
let bitmap = 0;
for (let i = 0; i < astr.length; ++i) {
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
const pos = astr[i].charCodeAt() - "a".charCodeAt();
if ((bitmap & (1 << pos)) != 0) {
return false;
}
bitmap |= (1 << pos);
bitmap |= 1 << pos;
}
return true;
};
Expand Down
22 changes: 11 additions & 11 deletions lcci/01.02.Check Permutation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ class Solution {

```js
var CheckPermutation = function (s1, s2) {
let n1 = s1.length,
n2 = s2.length;
if (n1 != n2) return false;
let counter = {};
for (let i = 0; i < n1; i++) {
let cur1 = s1.charAt(i),
cur2 = s2.charAt(i);
counter[cur1] = (counter[cur1] || 0) + 1;
counter[cur2] = (counter[cur2] || 0) - 1;
}
return Object.values(counter).every((v) => v == 0);
let n1 = s1.length,
n2 = s2.length;
if (n1 != n2) return false;
let counter = {};
for (let i = 0; i < n1; i++) {
let cur1 = s1.charAt(i),
cur2 = s2.charAt(i);
counter[cur1] = (counter[cur1] || 0) + 1;
counter[cur2] = (counter[cur2] || 0) - 1;
}
return Object.values(counter).every(v => v == 0);
};
```

Expand Down
22 changes: 11 additions & 11 deletions lcci/01.02.Check Permutation/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ class Solution {

```js
var CheckPermutation = function (s1, s2) {
let n1 = s1.length,
n2 = s2.length;
if (n1 != n2) return false;
let counter = {};
for (let i = 0; i < n1; i++) {
let cur1 = s1.charAt(i),
cur2 = s2.charAt(i);
counter[cur1] = (counter[cur1] || 0) + 1;
counter[cur2] = (counter[cur2] || 0) - 1;
}
return Object.values(counter).every((v) => v == 0);
let n1 = s1.length,
n2 = s2.length;
if (n1 != n2) return false;
let counter = {};
for (let i = 0; i < n1; i++) {
let cur1 = s1.charAt(i),
cur2 = s2.charAt(i);
counter[cur1] = (counter[cur1] || 0) + 1;
counter[cur2] = (counter[cur2] || 0) - 1;
}
return Object.values(counter).every(v => v == 0);
};
```

Expand Down
4 changes: 2 additions & 2 deletions lcci/01.03.String to URL/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ class Solution {
* @param {number} length
* @return {string}
*/
var replaceSpaces = function(S, length) {
return encodeURI(S.substring(0,length));
var replaceSpaces = function (S, length) {
return encodeURI(S.substring(0, length));
};
```

Expand Down
4 changes: 2 additions & 2 deletions lcci/01.03.String to URL/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class Solution {
* @param {number} length
* @return {string}
*/
var replaceSpaces = function(S, length) {
return encodeURI(S.substring(0,length));
var replaceSpaces = function (S, length) {
return encodeURI(S.substring(0, length));
};
```

Expand Down
11 changes: 6 additions & 5 deletions lcci/01.06.Compress String/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,19 @@ class Solution {
* @param {string} S
* @return {string}
*/
var compressString = function(S) {
var compressString = function (S) {
if (!S) return S;
let p = 0, q = 1;
let res = '';
let p = 0,
q = 1;
let res = "";
while (q < S.length) {
if (S[p] != S[q]) {
res += (S[p] + (q - p));
res += S[p] + (q - p);
p = q;
}
++q;
}
res += (S[p] + (q - p));
res += S[p] + (q - p);
return res.length < S.length ? res : S;
};
```
Expand Down
11 changes: 6 additions & 5 deletions lcci/01.06.Compress String/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,19 @@ class Solution {
* @param {string} S
* @return {string}
*/
var compressString = function(S) {
var compressString = function (S) {
if (!S) return S;
let p = 0, q = 1;
let res = '';
let p = 0,
q = 1;
let res = "";
while (q < S.length) {
if (S[p] != S[q]) {
res += (S[p] + (q - p));
res += S[p] + (q - p);
p = q;
}
++q;
}
res += (S[p] + (q - p));
res += S[p] + (q - p);
return res.length < S.length ? res : S;
};
```
Expand Down
4 changes: 2 additions & 2 deletions lcci/01.07.Rotate Matrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ class Solution {
* @param {number[][]} matrix
* @return {void} Do not return anything, modify matrix in-place instead.
*/
var rotate = function(matrix) {
var rotate = function (matrix) {
const n = matrix.length;
for (let i = 0; i < (n / 2); i++) {
for (let i = 0; i < n / 2; i++) {
for (let j = i; j < n - i - 1; j++) {
let t = matrix[i][j];
matrix[i][j] = matrix[n - j - 1][i];
Expand Down
Loading

0 comments on commit 1f54d3e

Please sign in to comment.