Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update format script #1038

Merged
merged 5 commits into from
Jun 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion basic/searching/BinarySearch/README.md
Original file line number Diff line number Diff line change
@@ -7,7 +7,8 @@
### 模板 1

```java
boolean check(int x) {}
boolean check(int x) {
}

int search(int left, int right) {
while (left < right) {
3 changes: 2 additions & 1 deletion basic/searching/BinarySearch/README_EN.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@
### Template 1

```java
boolean check(int x) {}
boolean check(int x) {
}

int search(int left, int right) {
while (left < right) {
2 changes: 1 addition & 1 deletion basic/sorting/BubbleSort/BubbleSort.go
Original file line number Diff line number Diff line change
@@ -19,4 +19,4 @@ func main() {
nums := []int{1, 2, 7, 9, 5, 8}
bubbleSort(nums)
fmt.Println(nums)
}
}
4 changes: 2 additions & 2 deletions basic/sorting/CountingSort/CountingSort.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package CountingSort
package main

func CountingSort(nums []int, min, max int) {
n := len(nums)
@@ -23,4 +23,4 @@ func CountingSort(nums []int, min, max int) {
for i, v := range r {
nums[i] = v
}
}
}
36 changes: 19 additions & 17 deletions basic/sorting/CountingSort/CountingSort.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
public static void sort(int[] nums, int min, int max) {
int n = nums.length;
int k = max - min + 1;
int[] c = new int[k];
for (int v : nums) {
c[v - min]++;
public class CountingSort {
public static void sort(int[] nums, int min, int max) {
int n = nums.length;
int k = max - min + 1;
int[] c = new int[k];
for (int v : nums) {
c[v - min]++;
}
for (int i = 1; i < k; i++) {
c[i] += c[i - 1];
}
int[] r = new int[n];
for (int i = n - 1; i >= 0; i--) {
int v = nums[i];
int a = c[v];
r[a - 1] = v + min;
c[v]--;
}
System.arraycopy(r, 0, nums, 0, n);
}
for (int i = 1; i < k; i++) {
c[i] += c[i - 1];
}
int[] r = new int[n];
for (int i = n - 1; i >= 0; i--) {
int v = nums[i];
int a = c[v];
r[a - 1] = v + min;
c[v]--;
}
System.arraycopy(r, 0, nums, 0, n);
}
34 changes: 19 additions & 15 deletions basic/sorting/CountingSort/README.md
Original file line number Diff line number Diff line change
@@ -17,22 +17,26 @@
### **Java**

```java
public static void sort(int[] nums, int min, int max) {
int[] c = new int[max - min + 1];
for (int v : nums) {
c[v - min]++;
public class CountingSort {
public static void sort(int[] nums, int min, int max) {
int n = nums.length;
int k = max - min + 1;
int[] c = new int[k];
for (int v : nums) {
c[v - min]++;
}
for (int i = 1; i < k; i++) {
c[i] += c[i - 1];
}
int[] r = new int[n];
for (int i = n - 1; i >= 0; i--) {
int v = nums[i];
int a = c[v];
r[a - 1] = v + min;
c[v]--;
}
System.arraycopy(r, 0, nums, 0, n);
}
for (int i = 1; i < c.length; i++) {
c[i] += c[i - 1];
}
int[] r = new int[nums.length];
for (int i = nums.length - 1; i >= 0; i--) {
int v = nums[i];
int a = c[v];
r[a - 1] = v + min;
c[v]--;
}
System.arraycopy(r, 0, nums, 0, r.length);
}
```

2 changes: 1 addition & 1 deletion basic/sorting/HeapSort/Main.go
Original file line number Diff line number Diff line change
@@ -48,4 +48,4 @@ func main() {
size--
down(1)
}
}
}
2 changes: 1 addition & 1 deletion basic/sorting/InsertionSort/InsertionSort.go
Original file line number Diff line number Diff line change
@@ -16,4 +16,4 @@ func main() {
nums := []int{1, 2, 7, 9, 5, 8}
insertionSort(nums)
fmt.Println(nums)
}
}
2 changes: 1 addition & 1 deletion basic/sorting/QuickSort/Main.go
Original file line number Diff line number Diff line change
@@ -42,4 +42,4 @@ func main() {
for _, v := range nums {
fmt.Printf("%d ", v)
}
}
}
6 changes: 4 additions & 2 deletions basic/sorting/QuickSort/README.md
Original file line number Diff line number Diff line change
@@ -12,8 +12,10 @@ void quickSort(int[] nums, int left, int right) {
int i = left - 1, j = right + 1;
int x = nums[left];
while (i < j) {
while (nums[++i] < x);
while (nums[--j] > x);
while (nums[++i] < x)
;
while (nums[--j] > x)
;
if (i < j) {
int t = nums[i];
nums[i] = nums[j];
2 changes: 1 addition & 1 deletion basic/sorting/SelectionSort/SelectionSort.go
Original file line number Diff line number Diff line change
@@ -18,4 +18,4 @@ func main() {
nums := []int{1, 2, 7, 9, 5, 8}
selectionSort(nums)
fmt.Println(nums)
}
}
2 changes: 1 addition & 1 deletion basic/sorting/ShellSort/ShellSort.go
Original file line number Diff line number Diff line change
@@ -19,4 +19,4 @@ func main() {
nums := []int{1, 2, 7, 9, 5, 8}
shellSort(nums)
fmt.Println(nums)
}
}
5 changes: 3 additions & 2 deletions lcci/01.02.Check Permutation/README.md
Original file line number Diff line number Diff line change
@@ -112,8 +112,9 @@ public:
bool CheckPermutation(string s1, string s2) {
if (s1.size() != s2.size()) return false;
int cnt[26] = {0};
for (char & c : s1) ++cnt[c - 'a'];
for (char & c : s2) if (--cnt[c - 'a'] < 0) return false;
for (char& c : s1) ++cnt[c - 'a'];
for (char& c : s2)
if (--cnt[c - 'a'] < 0) return false;
return true;
}
};
5 changes: 3 additions & 2 deletions lcci/01.02.Check Permutation/README_EN.md
Original file line number Diff line number Diff line change
@@ -92,8 +92,9 @@ public:
bool CheckPermutation(string s1, string s2) {
if (s1.size() != s2.size()) return false;
int cnt[26] = {0};
for (char & c : s1) ++cnt[c - 'a'];
for (char & c : s2) if (--cnt[c - 'a'] < 0) return false;
for (char& c : s1) ++cnt[c - 'a'];
for (char& c : s2)
if (--cnt[c - 'a'] < 0) return false;
return true;
}
};
2 changes: 1 addition & 1 deletion lcci/01.04.Palindrome Permutation/README.md
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ class Solution:
```java
class Solution {
public boolean canPermutePalindrome(String s) {
Map<Character, Integer> cnt = new HashMap<>();
Map<Character, Integer> cnt = new HashMap<>();
for (int i = 0; i < s.length(); ++i) {
cnt.merge(s.charAt(i), 1, Integer::sum);
}
2 changes: 1 addition & 1 deletion lcci/01.04.Palindrome Permutation/README_EN.md
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ class Solution:
```java
class Solution {
public boolean canPermutePalindrome(String s) {
Map<Character, Integer> cnt = new HashMap<>();
Map<Character, Integer> cnt = new HashMap<>();
for (int i = 0; i < s.length(); ++i) {
cnt.merge(s.charAt(i), 1, Integer::sum);
}
8 changes: 4 additions & 4 deletions lcci/01.08.Zero Matrix/README.md
Original file line number Diff line number Diff line change
@@ -400,11 +400,11 @@ var setZeroes = function (matrix) {
### **C**

```c
void setZeroes(int **matrix, int matrixSize, int *matrixColSize) {
void setZeroes(int** matrix, int matrixSize, int* matrixColSize) {
int m = matrixSize;
int n = matrixColSize[0];
int *rows = (int *) malloc(sizeof(int) * m);
int *cols = (int *) malloc(sizeof(int) * n);
int* rows = (int*) malloc(sizeof(int) * m);
int* cols = (int*) malloc(sizeof(int) * n);
memset(rows, 0, sizeof(int) * m);
memset(cols, 0, sizeof(int) * n);
for (int i = 0; i < m; i++) {
@@ -428,7 +428,7 @@ void setZeroes(int **matrix, int matrixSize, int *matrixColSize) {
```

```c
void setZeroes(int **matrix, int matrixSize, int *matrixColSize) {
void setZeroes(int** matrix, int matrixSize, int* matrixColSize) {
int m = matrixSize;
int n = matrixColSize[0];
int l0 = 0;
8 changes: 4 additions & 4 deletions lcci/01.08.Zero Matrix/README_EN.md
Original file line number Diff line number Diff line change
@@ -405,11 +405,11 @@ var setZeroes = function (matrix) {
### **C**

```c
void setZeroes(int **matrix, int matrixSize, int *matrixColSize) {
void setZeroes(int** matrix, int matrixSize, int* matrixColSize) {
int m = matrixSize;
int n = matrixColSize[0];
int *rows = (int *) malloc(sizeof(int) * m);
int *cols = (int *) malloc(sizeof(int) * n);
int* rows = (int*) malloc(sizeof(int) * m);
int* cols = (int*) malloc(sizeof(int) * n);
memset(rows, 0, sizeof(int) * m);
memset(cols, 0, sizeof(int) * n);
for (int i = 0; i < m; i++) {
@@ -433,7 +433,7 @@ void setZeroes(int **matrix, int matrixSize, int *matrixColSize) {
```

```c
void setZeroes(int **matrix, int matrixSize, int *matrixColSize) {
void setZeroes(int** matrix, int matrixSize, int* matrixColSize) {
int m = matrixSize;
int n = matrixColSize[0];
int l0 = 0;
6 changes: 3 additions & 3 deletions lcci/04.01.Route Between Nodes/README.md
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ public:
bool findWhetherExistsPath(int n, vector<vector<int>>& graph, int start, int target) {
unordered_map<int, vector<int>> g;
for (auto& e : graph) g[e[0]].push_back(e[1]);
unordered_set<int> vis {{start}};
unordered_set<int> vis{{start}};
return dfs(start, target, g, vis);
}

@@ -176,8 +176,8 @@ public:
bool findWhetherExistsPath(int n, vector<vector<int>>& graph, int start, int target) {
unordered_map<int, vector<int>> g;
for (auto& e : graph) g[e[0]].push_back(e[1]);
queue<int> q {{start}};
unordered_set<int> vis {{start}};
queue<int> q{{start}};
unordered_set<int> vis{{start}};
while (!q.empty()) {
int u = q.front();
if (u == target) return true;
6 changes: 3 additions & 3 deletions lcci/04.01.Route Between Nodes/README_EN.md
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ public:
bool findWhetherExistsPath(int n, vector<vector<int>>& graph, int start, int target) {
unordered_map<int, vector<int>> g;
for (auto& e : graph) g[e[0]].push_back(e[1]);
unordered_set<int> vis {{start}};
unordered_set<int> vis{{start}};
return dfs(start, target, g, vis);
}

@@ -175,8 +175,8 @@ public:
bool findWhetherExistsPath(int n, vector<vector<int>>& graph, int start, int target) {
unordered_map<int, vector<int>> g;
for (auto& e : graph) g[e[0]].push_back(e[1]);
queue<int> q {{start}};
unordered_set<int> vis {{start}};
queue<int> q{{start}};
unordered_set<int> vis{{start}};
while (!q.empty()) {
int u = q.front();
if (u == target) return true;
6 changes: 3 additions & 3 deletions lcci/04.06.Successor/README.md
Original file line number Diff line number Diff line change
@@ -156,9 +156,9 @@ public:
*/
class Solution {
public:
TreeNode *inorderSuccessor(TreeNode *root, TreeNode *p) {
stack<TreeNode *> stk;
TreeNode *cur = root;
TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) {
stack<TreeNode*> stk;
TreeNode* cur = root;
while (cur != nullptr || !stk.empty()) {
if (cur == nullptr) {
cur = stk.top();
6 changes: 3 additions & 3 deletions lcci/04.06.Successor/README_EN.md
Original file line number Diff line number Diff line change
@@ -169,9 +169,9 @@ public:
*/
class Solution {
public:
TreeNode *inorderSuccessor(TreeNode *root, TreeNode *p) {
stack<TreeNode *> stk;
TreeNode *cur = root;
TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) {
stack<TreeNode*> stk;
TreeNode* cur = root;
while (cur != nullptr || !stk.empty()) {
if (cur == nullptr) {
cur = stk.top();
9 changes: 3 additions & 6 deletions lcci/08.04.Power Set/README.md
Original file line number Diff line number Diff line change
@@ -160,13 +160,10 @@ public:
vector<vector<int>> ans;
vector<int> t;
int n = nums.size();
for (int mask = 0; mask < 1 << n; ++mask)
{
for (int mask = 0; mask < 1 << n; ++mask) {
t.clear();
for (int i = 0; i < n; ++i)
{
if ((mask >> i) & 1)
{
for (int i = 0; i < n; ++i) {
if ((mask >> i) & 1) {
t.push_back(nums[i]);
}
}
9 changes: 3 additions & 6 deletions lcci/08.04.Power Set/README_EN.md
Original file line number Diff line number Diff line change
@@ -153,13 +153,10 @@ public:
vector<vector<int>> ans;
vector<int> t;
int n = nums.size();
for (int mask = 0; mask < 1 << n; ++mask)
{
for (int mask = 0; mask < 1 << n; ++mask) {
t.clear();
for (int i = 0; i < n; ++i)
{
if ((mask >> i) & 1)
{
for (int i = 0; i < n; ++i) {
if ((mask >> i) & 1) {
t.push_back(nums[i]);
}
}
3 changes: 2 additions & 1 deletion lcci/08.10.Color Fill/README.md
Original file line number Diff line number Diff line change
@@ -112,7 +112,8 @@ class Solution {
}

private void dfs(int i, int j) {
if (i < 0 || i >= image.length || j < 0 || j >= image[0].length || image[i][j] != oc || image[i][j] == nc) {
if (i < 0 || i >= image.length || j < 0 || j >= image[0].length || image[i][j] != oc
|| image[i][j] == nc) {
return;
}
image[i][j] = nc;
3 changes: 2 additions & 1 deletion lcci/08.10.Color Fill/README_EN.md
Original file line number Diff line number Diff line change
@@ -109,7 +109,8 @@ class Solution {
}

private void dfs(int i, int j) {
if (i < 0 || i >= image.length || j < 0 || j >= image[0].length || image[i][j] != oc || image[i][j] == nc) {
if (i < 0 || i >= image.length || j < 0 || j >= image[0].length || image[i][j] != oc
|| image[i][j] == nc) {
return;
}
image[i][j] = nc;
2 changes: 1 addition & 1 deletion lcci/10.10.Rank from Stream/README.md
Original file line number Diff line number Diff line change
@@ -163,7 +163,7 @@ public:

BinaryIndexedTree(int _n)
: n(_n)
, c(_n + 1) { }
, c(_n + 1) {}

void update(int x, int delta) {
while (x <= n) {
2 changes: 1 addition & 1 deletion lcci/10.10.Rank from Stream/README_EN.md
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ public:

BinaryIndexedTree(int _n)
: n(_n)
, c(_n + 1) { }
, c(_n + 1) {}

void update(int x, int delta) {
while (x <= n) {
Loading