Skip to content

Commit e24f19f

Browse files
authored
chore: adjust prettier printWidth (doocs#1553)
* chore: adjust prettier printWidth * chore: reformat
1 parent ab45c7a commit e24f19f

File tree

803 files changed

+1114
-4563
lines changed

Some content is hidden

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

803 files changed

+1114
-4563
lines changed

.prettierrc

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"semi": true,
55
"singleQuote": true,
66
"trailingComma": "all",
7+
"printWidth": 100,
78
"bracketSpacing": true,
89
"arrowParens": "avoid",
910
"phpVersion": "8.1",

lcci/02.05.Sum Lists/README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
199199
* }
200200
*/
201201

202-
function addTwoNumbers(
203-
l1: ListNode | null,
204-
l2: ListNode | null,
205-
): ListNode | null {
202+
function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {
206203
if (l1 == null || l2 == null) {
207204
return l1 && l2;
208205
}

lcci/02.05.Sum Lists/README_EN.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,7 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
194194
* }
195195
*/
196196

197-
function addTwoNumbers(
198-
l1: ListNode | null,
199-
l2: ListNode | null,
200-
): ListNode | null {
197+
function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {
201198
if (l1 == null || l2 == null) {
202199
return l1 && l2;
203200
}

lcci/02.05.Sum Lists/Solution.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
* }
1111
*/
1212

13-
function addTwoNumbers(
14-
l1: ListNode | null,
15-
l2: ListNode | null,
16-
): ListNode | null {
13+
function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {
1714
if (l1 == null || l2 == null) {
1815
return l1 && l2;
1916
}

lcci/03.02.Min Stack/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ class MinStack {
172172
}
173173

174174
getMin(): number {
175-
return this.mins.length == 0
176-
? Infinity
177-
: this.mins[this.mins.length - 1];
175+
return this.mins.length == 0 ? Infinity : this.mins[this.mins.length - 1];
178176
}
179177
}
180178

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,7 @@ function isValidBST(root: TreeNode | null): boolean {
229229
if (val <= min || val >= max) {
230230
return false;
231231
}
232-
return (
233-
dfs(left, min, Math.min(val, max)) &&
234-
dfs(right, Math.max(val, min), max)
235-
);
232+
return dfs(left, min, Math.min(val, max)) && dfs(right, Math.max(val, min), max);
236233
};
237234
return dfs(left, -Infinity, val) && dfs(right, val, Infinity);
238235
}

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,7 @@ function isValidBST(root: TreeNode | null): boolean {
258258
if (val <= min || val >= max) {
259259
return false;
260260
}
261-
return (
262-
dfs(left, min, Math.min(val, max)) &&
263-
dfs(right, Math.max(val, min), max)
264-
);
261+
return dfs(left, min, Math.min(val, max)) && dfs(right, Math.max(val, min), max);
265262
};
266263
return dfs(left, -Infinity, val) && dfs(right, val, Infinity);
267264
}

lcci/04.10.Check SubTree/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ function checkSubTree(t1: TreeNode | null, t2: TreeNode | null): boolean {
163163
return false;
164164
}
165165
if (t1.val === t2.val) {
166-
return (
167-
checkSubTree(t1.left, t2.left) && checkSubTree(t1.right, t2.right)
168-
);
166+
return checkSubTree(t1.left, t2.left) && checkSubTree(t1.right, t2.right);
169167
}
170168
return checkSubTree(t1.left, t2) || checkSubTree(t1.right, t2);
171169
}

lcci/04.10.Check SubTree/README_EN.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ function checkSubTree(t1: TreeNode | null, t2: TreeNode | null): boolean {
166166
return false;
167167
}
168168
if (t1.val === t2.val) {
169-
return (
170-
checkSubTree(t1.left, t2.left) && checkSubTree(t1.right, t2.right)
171-
);
169+
return checkSubTree(t1.left, t2.left) && checkSubTree(t1.right, t2.right);
172170
}
173171
return checkSubTree(t1.left, t2) || checkSubTree(t1.right, t2);
174172
}

lcci/04.10.Check SubTree/Solution.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ function checkSubTree(t1: TreeNode | null, t2: TreeNode | null): boolean {
2020
return false;
2121
}
2222
if (t1.val === t2.val) {
23-
return (
24-
checkSubTree(t1.left, t2.left) && checkSubTree(t1.right, t2.right)
25-
);
23+
return checkSubTree(t1.left, t2.left) && checkSubTree(t1.right, t2.right);
2624
}
2725
return checkSubTree(t1.left, t2) || checkSubTree(t1.right, t2);
2826
}

lcci/16.07.Maximum/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ func maximum(a int, b int) int {
7575

7676
```ts
7777
function maximum(a: number, b: number): number {
78-
const k: number = Number(
79-
((BigInt(a) - BigInt(b)) >> BigInt(63)) & BigInt(1),
80-
);
78+
const k: number = Number(((BigInt(a) - BigInt(b)) >> BigInt(63)) & BigInt(1));
8179
return a * (k ^ 1) + b * k;
8280
}
8381
```

lcci/16.07.Maximum/README_EN.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ func maximum(a int, b int) int {
6363

6464
```ts
6565
function maximum(a: number, b: number): number {
66-
const k: number = Number(
67-
((BigInt(a) - BigInt(b)) >> BigInt(63)) & BigInt(1),
68-
);
66+
const k: number = Number(((BigInt(a) - BigInt(b)) >> BigInt(63)) & BigInt(1));
6967
return a * (k ^ 1) + b * k;
7068
}
7169
```

lcci/16.07.Maximum/Solution.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
function maximum(a: number, b: number): number {
2-
const k: number = Number(
3-
((BigInt(a) - BigInt(b)) >> BigInt(63)) & BigInt(1),
4-
);
2+
const k: number = Number(((BigInt(a) - BigInt(b)) >> BigInt(63)) & BigInt(1));
53
return a * (k ^ 1) + b * k;
64
}

lcci/16.15.Master Mind/README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ var masterMind = function (solution, guess) {
140140
counts2[s2] += 1;
141141
}
142142
}
143-
let res2 = ['R', 'G', 'B', 'Y'].reduce(
144-
(a, c) => a + Math.min(counts1[c], counts2[c]),
145-
0,
146-
);
143+
let res2 = ['R', 'G', 'B', 'Y'].reduce((a, c) => a + Math.min(counts1[c], counts2[c]), 0);
147144
return [res1, res2];
148145
};
149146
```

lcci/16.15.Master Mind/README_EN.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ var masterMind = function (solution, guess) {
133133
counts2[s2] += 1;
134134
}
135135
}
136-
let res2 = ['R', 'G', 'B', 'Y'].reduce(
137-
(a, c) => a + Math.min(counts1[c], counts2[c]),
138-
0,
139-
);
136+
let res2 = ['R', 'G', 'B', 'Y'].reduce((a, c) => a + Math.min(counts1[c], counts2[c]), 0);
140137
return [res1, res2];
141138
};
142139
```

lcci/16.15.Master Mind/Solution.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ var masterMind = function (solution, guess) {
1717
counts2[s2] += 1;
1818
}
1919
}
20-
let res2 = ['R', 'G', 'B', 'Y'].reduce(
21-
(a, c) => a + Math.min(counts1[c], counts2[c]),
22-
0,
23-
);
20+
let res2 = ['R', 'G', 'B', 'Y'].reduce((a, c) => a + Math.min(counts1[c], counts2[c]), 0);
2421
return [res1, res2];
2522
};

lcci/17.23.Max Black Square/README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,8 @@ func findSquare(matrix [][]int) []int {
207207
```ts
208208
function findSquare(matrix: number[][]): number[] {
209209
const n = matrix.length;
210-
const down: number[][] = new Array(n)
211-
.fill(0)
212-
.map(() => new Array(n).fill(0));
213-
const right: number[][] = new Array(n)
214-
.fill(0)
215-
.map(() => new Array(n).fill(0));
210+
const down: number[][] = new Array(n).fill(0).map(() => new Array(n).fill(0));
211+
const right: number[][] = new Array(n).fill(0).map(() => new Array(n).fill(0));
216212
for (let i = n - 1; i >= 0; --i) {
217213
for (let j = n - 1; j >= 0; --j) {
218214
if (matrix[i][j] === 0) {

lcci/17.23.Max Black Square/README_EN.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,8 @@ func findSquare(matrix [][]int) []int {
185185
```ts
186186
function findSquare(matrix: number[][]): number[] {
187187
const n = matrix.length;
188-
const down: number[][] = new Array(n)
189-
.fill(0)
190-
.map(() => new Array(n).fill(0));
191-
const right: number[][] = new Array(n)
192-
.fill(0)
193-
.map(() => new Array(n).fill(0));
188+
const down: number[][] = new Array(n).fill(0).map(() => new Array(n).fill(0));
189+
const right: number[][] = new Array(n).fill(0).map(() => new Array(n).fill(0));
194190
for (let i = n - 1; i >= 0; --i) {
195191
for (let j = n - 1; j >= 0; --j) {
196192
if (matrix[i][j] === 0) {

lcci/17.23.Max Black Square/Solution.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
function findSquare(matrix: number[][]): number[] {
22
const n = matrix.length;
3-
const down: number[][] = new Array(n)
4-
.fill(0)
5-
.map(() => new Array(n).fill(0));
6-
const right: number[][] = new Array(n)
7-
.fill(0)
8-
.map(() => new Array(n).fill(0));
3+
const down: number[][] = new Array(n).fill(0).map(() => new Array(n).fill(0));
4+
const right: number[][] = new Array(n).fill(0).map(() => new Array(n).fill(0));
95
for (let i = n - 1; i >= 0; --i) {
106
for (let j = n - 1; j >= 0; --j) {
117
if (matrix[i][j] === 0) {

lcof/面试题12. 矩阵中的路径/README.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,7 @@ function exist(board: string[][], word: string): boolean {
244244
}
245245
const temp = board[i][j];
246246
board[i][j] = ' ';
247-
if (
248-
dfs(i + 1, j, k) ||
249-
dfs(i, j + 1, k) ||
250-
dfs(i - 1, j, k) ||
251-
dfs(i, j - 1, k)
252-
) {
247+
if (dfs(i + 1, j, k) || dfs(i, j + 1, k) || dfs(i - 1, j, k) || dfs(i, j - 1, k)) {
253248
return true;
254249
}
255250
board[i][j] = temp;

lcof/面试题12. 矩阵中的路径/Solution.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ function exist(board: string[][], word: string): boolean {
1010
}
1111
const temp = board[i][j];
1212
board[i][j] = ' ';
13-
if (
14-
dfs(i + 1, j, k) ||
15-
dfs(i, j + 1, k) ||
16-
dfs(i - 1, j, k) ||
17-
dfs(i, j - 1, k)
18-
) {
13+
if (dfs(i + 1, j, k) || dfs(i, j + 1, k) || dfs(i - 1, j, k) || dfs(i, j - 1, k)) {
1914
return true;
2015
}
2116
board[i][j] = temp;

lcof/面试题19. 正则表达式匹配/README.md

+2-9
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,10 @@ var isMatch = function (s, p) {
317317
}
318318
let res = -1;
319319
if (j + 1 < n && p[j + 1] === '*') {
320-
if (
321-
dfs(i, j + 2) ||
322-
(i < m && (s[i] == p[j] || p[j] == '.') && dfs(i + 1, j))
323-
) {
320+
if (dfs(i, j + 2) || (i < m && (s[i] == p[j] || p[j] == '.') && dfs(i + 1, j))) {
324321
res = 1;
325322
}
326-
} else if (
327-
i < m &&
328-
(s[i] == p[j] || p[j] == '.') &&
329-
dfs(i + 1, j + 1)
330-
) {
323+
} else if (i < m && (s[i] == p[j] || p[j] == '.') && dfs(i + 1, j + 1)) {
331324
res = 1;
332325
}
333326
f[i][j] = res;

lcof/面试题25. 合并两个排序的链表/README.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,7 @@ var mergeTwoLists = function (l1, l2) {
337337
* }
338338
*/
339339

340-
function mergeTwoLists(
341-
l1: ListNode | null,
342-
l2: ListNode | null,
343-
): ListNode | null {
340+
function mergeTwoLists(l1: ListNode | null, l2: ListNode | null): ListNode | null {
344341
const dummy = new ListNode(0);
345342
let cur = dummy;
346343
while (l1 && l2) {
@@ -371,10 +368,7 @@ function mergeTwoLists(
371368
* }
372369
*/
373370

374-
function mergeTwoLists(
375-
l1: ListNode | null,
376-
l2: ListNode | null,
377-
): ListNode | null {
371+
function mergeTwoLists(l1: ListNode | null, l2: ListNode | null): ListNode | null {
378372
if (l1 == null || l2 == null) {
379373
return l1 || l2;
380374
}

lcof/面试题25. 合并两个排序的链表/Solution.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
* }
1111
*/
1212

13-
function mergeTwoLists(
14-
l1: ListNode | null,
15-
l2: ListNode | null,
16-
): ListNode | null {
13+
function mergeTwoLists(l1: ListNode | null, l2: ListNode | null): ListNode | null {
1714
const dummy = new ListNode(0);
1815
let cur = dummy;
1916
while (l1 && l2) {

lcof/面试题30. 包含min函数的栈/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ class MinStack {
236236
}
237237

238238
getMin(): number {
239-
return this.mins.length == 0
240-
? Infinity
241-
: this.mins[this.mins.length - 1];
239+
return this.mins.length == 0 ? Infinity : this.mins[this.mins.length - 1];
242240
}
243241
}
244242

lcof/面试题41. 数据流中的中位数/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ MedianFinder.prototype.addNum = function (num) {
279279
*/
280280
MedianFinder.prototype.findMedian = function () {
281281
let mid = ~~(this.val.length / 2);
282-
return this.val.length % 2
283-
? this.val[mid]
284-
: (this.val[mid - 1] + this.val[mid]) / 2;
282+
return this.val.length % 2 ? this.val[mid] : (this.val[mid - 1] + this.val[mid]) / 2;
285283
};
286284
```
287285

lcof/面试题41. 数据流中的中位数/Solution.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,5 @@ MedianFinder.prototype.addNum = function (num) {
2828
*/
2929
MedianFinder.prototype.findMedian = function () {
3030
let mid = ~~(this.val.length / 2);
31-
return this.val.length % 2
32-
? this.val[mid]
33-
: (this.val[mid - 1] + this.val[mid]) / 2;
31+
return this.val.length % 2 ? this.val[mid] : (this.val[mid - 1] + this.val[mid]) / 2;
3432
};

lcof/面试题45. 把数组排成最小的数/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ var minNumber = function (nums) {
133133

134134
```ts
135135
function minNumber(nums: number[]): string {
136-
return nums
137-
.sort((a, b) => Number(`${a}${b}`) - Number(`${b}${a}`))
138-
.join('');
136+
return nums.sort((a, b) => Number(`${a}${b}`) - Number(`${b}${a}`)).join('');
139137
}
140138
```
141139

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
function minNumber(nums: number[]): string {
2-
return nums
3-
.sort((a, b) => Number(`${a}${b}`) - Number(`${b}${a}`))
4-
.join('');
2+
return nums.sort((a, b) => Number(`${a}${b}`) - Number(`${b}${a}`)).join('');
53
}

lcof/面试题47. 礼物的最大价值/README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ var maxValue = function (grid) {
213213
const f = new Array(2).fill(0).map(() => new Array(n + 1).fill(0));
214214
for (let i = 1; i <= m; ++i) {
215215
for (let j = 1; j <= n; ++j) {
216-
f[i & 1][j] =
217-
Math.max(f[(i & 1) ^ 1][j], f[i & 1][j - 1]) +
218-
grid[i - 1][j - 1];
216+
f[i & 1][j] = Math.max(f[(i & 1) ^ 1][j], f[i & 1][j - 1]) + grid[i - 1][j - 1];
219217
}
220218
}
221219
return f[m & 1][n];
@@ -245,9 +243,7 @@ function maxValue(grid: number[][]): number {
245243
const f = Array.from({ length: 2 }, _ => new Array(n + 1).fill(0));
246244
for (let i = 1; i <= m; ++i) {
247245
for (let j = 1; j <= n; ++j) {
248-
f[i & 1][j] =
249-
Math.max(f[(i & 1) ^ 1][j], f[i & 1][j - 1]) +
250-
grid[i - 1][j - 1];
246+
f[i & 1][j] = Math.max(f[(i & 1) ^ 1][j], f[i & 1][j - 1]) + grid[i - 1][j - 1];
251247
}
252248
}
253249
return f[m & 1][n];

lcof/面试题47. 礼物的最大价值/Solution.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ var maxValue = function (grid) {
88
const f = new Array(2).fill(0).map(() => new Array(n + 1).fill(0));
99
for (let i = 1; i <= m; ++i) {
1010
for (let j = 1; j <= n; ++j) {
11-
f[i & 1][j] =
12-
Math.max(f[(i & 1) ^ 1][j], f[i & 1][j - 1]) +
13-
grid[i - 1][j - 1];
11+
f[i & 1][j] = Math.max(f[(i & 1) ^ 1][j], f[i & 1][j - 1]) + grid[i - 1][j - 1];
1412
}
1513
}
1614
return f[m & 1][n];

lcof/面试题47. 礼物的最大价值/Solution.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ function maxValue(grid: number[][]): number {
44
const f = Array.from({ length: 2 }, _ => new Array(n + 1).fill(0));
55
for (let i = 1; i <= m; ++i) {
66
for (let j = 1; j <= n; ++j) {
7-
f[i & 1][j] =
8-
Math.max(f[(i & 1) ^ 1][j], f[i & 1][j - 1]) +
9-
grid[i - 1][j - 1];
7+
f[i & 1][j] = Math.max(f[(i & 1) ^ 1][j], f[i & 1][j - 1]) + grid[i - 1][j - 1];
108
}
119
}
1210
return f[m & 1][n];

0 commit comments

Comments
 (0)