Skip to content

Commit

Permalink
style: format code and documents
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Jul 4, 2022
1 parent cfe9665 commit e3c003b
Show file tree
Hide file tree
Showing 29 changed files with 102 additions and 66 deletions.
1 change: 0 additions & 1 deletion lcci/16.10.Living People/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ function maxAliveYear(birth: number[], death: number[]): number {
}
return res;
}

```

### **Rust**
Expand Down
1 change: 0 additions & 1 deletion lcci/16.10.Living People/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ function maxAliveYear(birth: number[], death: number[]): number {
}
return res;
}

```

### **Rust**
Expand Down
2 changes: 1 addition & 1 deletion lcp/LCP 34. 二叉树染色/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Solution:
for j in range(k + 1):
ans[0] = max(ans[0], l[i] + r[j])
return ans

return max(dfs(root))
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Solution:
else:
ans.append(a * b)
return ans

return dfs(expression)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Solution:
else:
ans.append(a * b)
return ans

return dfs(expression)
```

Expand Down
2 changes: 0 additions & 2 deletions solution/0300-0399/0336.Palindrome Pairs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
<strong>输出:</strong>[[0,1],[1,0]]
</pre>



<p><strong>提示:</strong></p>

<ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ for (int i = 0; i < n - 1; i += 2) {
return nums[n - 1];
```

偶数下标:当 `nums[i] != nums[i + 1] && i % 2 == 0` 成立,结果便是 `nums[i]`
奇数下标:当 `nums[i] != nums[i - 1] && i % 2 == 1` 成立,结果便是 `nums[i - 1]`
偶数下标:当 `nums[i] != nums[i + 1] && i % 2 == 0` 成立,结果便是 `nums[i]`
奇数下标:当 `nums[i] != nums[i - 1] && i % 2 == 1` 成立,结果便是 `nums[i - 1]`

于是二分模板就有了:

Expand Down
2 changes: 0 additions & 2 deletions solution/0500-0599/0554.Brick Wall/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
<strong>输出:</strong>3
</pre>



<p><strong>提示:</strong></p>

<ul>
Expand Down
2 changes: 0 additions & 2 deletions solution/0700-0799/0745.Prefix and Suffix Search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ WordFilter wordFilter = new WordFilter(["apple"]);
wordFilter.f("a", "e"); // 返回 0 ,因为下标为 0 的单词的 prefix = "a" 且 suffix = 'e" 。
</pre>



<p><strong>提示:</strong></p>

<ul>
Expand Down
2 changes: 0 additions & 2 deletions solution/0700-0799/0775.Global and Local Inversions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
<strong>解释:</strong>有 2 个全局倒置,和 1 个局部倒置。
</pre>



<p><strong>提示:</strong></p>

<ul>
Expand Down
2 changes: 0 additions & 2 deletions solution/0800-0899/0830.Positions of Large Groups/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
<strong>输出:</strong>[]
</pre>



<p><strong>提示:</strong></p>

<ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Solution {
this.questions = questions;
memo = new long[questions.length];
Arrays.fill(memo, -1);
return dfs(0);
return dfs(0);
}

private long dfs(int i) {
Expand All @@ -117,7 +117,7 @@ class Solution {
public:
long long mostPoints(vector<vector<int>>& questions) {
vector<long long> memo(questions.size(), -1);
return dfs(0, questions, memo);
return dfs(0, questions, memo);
}

long long dfs(int i, vector<vector<int>>& questions, vector<long long>& memo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Solution {
this.questions = questions;
memo = new long[questions.length];
Arrays.fill(memo, -1);
return dfs(0);
return dfs(0);
}

private long dfs(int i) {
Expand All @@ -107,7 +107,7 @@ class Solution {
public:
long long mostPoints(vector<vector<int>>& questions) {
vector<long long> memo(questions.size(), -1);
return dfs(0, questions, memo);
return dfs(0, questions, memo);
}

long long dfs(int i, vector<vector<int>>& questions, vector<long long>& memo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ func countHousePlacements(n int) int {
```ts
function countHousePlacements(n: number): number {
const mod = BigInt(10 ** 9 + 7);
let pre = 1n, count = 2n;
let pre = 1n,
count = 2n;
for (let i = 2; i <= n; i++) {
[count, pre] = [(count + pre) % mod, count];
}
return Number(count ** 2n % mod);
};
}
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ func countHousePlacements(n int) int {
```ts
function countHousePlacements(n: number): number {
const mod = BigInt(10 ** 9 + 7);
let pre = 1n, count = 2n;
let pre = 1n,
count = 2n;
for (let i = 2; i <= n; i++) {
[count, pre] = [(count + pre) % mod, count];
}
return Number(count ** 2n % mod);
};
}
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ It can be proven that 3 days is the minimum number of days needed.
<li><code>1 &lt;= jobs[i], workers[i] &lt;= 10<sup>5</sup></code></li>
</ul>


## 解法

<!-- 这里可写通用的实现逻辑 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ It can be proven that 3 days is the minimum number of days needed.
<li><code>1 &lt;= jobs[i], workers[i] &lt;= 10<sup>5</sup></code></li>
</ul>


## Solutions

<!-- tabs:start -->
Expand Down
5 changes: 3 additions & 2 deletions solution/2300-2399/2325.Decode the Message/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ func decodeMessage(key string, message string) string {
```ts
function decodeMessage(key: string, message: string): string {
let decodeMap = new Map();
const m = key.length, n = 26;
const m = key.length,
n = 26;
for (let i = 0, j = 0; i < m; i++) {
let char = key.charAt(i);
if (char != ' ' && !decodeMap.has(char)) {
Expand All @@ -169,7 +170,7 @@ function decodeMessage(key: string, message: string): string {
ans.push(char == ' ' ? ' ' : decodeMap.get(char));
}
return ans.join('');
};
}
```

### **...**
Expand Down
5 changes: 3 additions & 2 deletions solution/2300-2399/2325.Decode the Message/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func decodeMessage(key string, message string) string {
```ts
function decodeMessage(key: string, message: string): string {
let decodeMap = new Map();
const m = key.length, n = 26;
const m = key.length,
n = 26;
for (let i = 0, j = 0; i < m; i++) {
let char = key.charAt(i);
if (char != ' ' && !decodeMap.has(char)) {
Expand All @@ -155,7 +156,7 @@ function decodeMessage(key: string, message: string): string {
ans.push(char == ' ' ? ' ' : decodeMap.get(char));
}
return ans.join('');
};
}
```

### **...**
Expand Down
5 changes: 3 additions & 2 deletions solution/2300-2399/2325.Decode the Message/Solution.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function decodeMessage(key: string, message: string): string {
let decodeMap = new Map();
const m = key.length, n = 26;
const m = key.length,
n = 26;
for (let i = 0, j = 0; i < m; i++) {
let char = key.charAt(i);
if (char != ' ' && !decodeMap.has(char)) {
Expand All @@ -13,4 +14,4 @@ function decodeMessage(key: string, message: string): string {
ans.push(char == ' ' ? ' ' : decodeMap.get(char));
}
return ans.join('');
};
}
15 changes: 11 additions & 4 deletions solution/2300-2399/2326.Spiral Matrix IV/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,17 @@ func spiralMatrix(m int, n int, head *ListNode) [][]int {
* }
*/

function spiralMatrix(m: number, n: number, head: ListNode | null): number[][] {
const dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]];
function spiralMatrix(m: number, n: number, head: ListNode | null): number[][] {
const dirs = [
[0, 1],
[1, 0],
[0, -1],
[-1, 0],
];
let ans = Array.from({ length: m }, v => new Array(n).fill(-1));
let i = 0, j = 0, k = 0;
let i = 0,
j = 0,
k = 0;
while (head) {
ans[i][j] = head.val;
head = head.next;
Expand All @@ -234,7 +241,7 @@ func spiralMatrix(m int, n int, head *ListNode) [][]int {
j = j + dirs[k][1];
}
return ans;
};
}
```

### **...**
Expand Down
15 changes: 11 additions & 4 deletions solution/2300-2399/2326.Spiral Matrix IV/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,17 @@ func spiralMatrix(m int, n int, head *ListNode) [][]int {
* }
*/

function spiralMatrix(m: number, n: number, head: ListNode | null): number[][] {
const dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]];
function spiralMatrix(m: number, n: number, head: ListNode | null): number[][] {
const dirs = [
[0, 1],
[1, 0],
[0, -1],
[-1, 0],
];
let ans = Array.from({ length: m }, v => new Array(n).fill(-1));
let i = 0, j = 0, k = 0;
let i = 0,
j = 0,
k = 0;
while (head) {
ans[i][j] = head.val;
head = head.next;
Expand All @@ -226,7 +233,7 @@ func spiralMatrix(m int, n int, head *ListNode) [][]int {
j = j + dirs[k][1];
}
return ans;
};
}
```

### **...**
Expand Down
15 changes: 11 additions & 4 deletions solution/2300-2399/2326.Spiral Matrix IV/Solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@
* }
*/

function spiralMatrix(m: number, n: number, head: ListNode | null): number[][] {
const dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]];
function spiralMatrix(m: number, n: number, head: ListNode | null): number[][] {
const dirs = [
[0, 1],
[1, 0],
[0, -1],
[-1, 0],
];
let ans = Array.from({ length: m }, v => new Array(n).fill(-1));
let i = 0, j = 0, k = 0;
let i = 0,
j = 0,
k = 0;
while (head) {
ans[i][j] = head.val;
head = head.next;
Expand All @@ -26,4 +33,4 @@
j = j + dirs[k][1];
}
return ans;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function peopleAwareOfSecret(n: number, delay: number, forget: number): number {
}
}
return Number(pre % BigInt(10 ** 9 + 7));
};
}
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function peopleAwareOfSecret(n: number, delay: number, forget: number): number {
}
}
return Number(pre % BigInt(10 ** 9 + 7));
};
}
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ function peopleAwareOfSecret(n: number, delay: number, forget: number): number {
}
}
return Number(pre % BigInt(10 ** 9 + 7));
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,24 @@ func countPaths(grid [][]int) int {
```ts
function countPaths(grid: number[][]): number {
const mod = BigInt(10 ** 9 + 7);
const dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]];
const m = grid.length, n = grid[0].length;
const dirs = [
[0, 1],
[1, 0],
[0, -1],
[-1, 0],
];
const m = grid.length,
n = grid[0].length;
const dp = Array.from({ length: m }, v => new Array(n).fill(-1n));

function dfs (x, y) {
function dfs(x, y) {
if (dp[x][y] != -1) return dp[x][y];
let count = 1n;
for (let [dx, dy] of dirs) {
let i = x + dx, j = y + dy;
if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] <= grid[x][y]) continue;
let i = x + dx,
j = y + dy;
if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] <= grid[x][y])
continue;
count = (count + dfs(i, j)) % mod;
}
dp[x][y] = count;
Expand All @@ -219,7 +227,7 @@ function countPaths(grid: number[][]): number {
}
}
return Number(sum);
};
}
```

### **...**
Expand Down
Loading

0 comments on commit e3c003b

Please sign in to comment.