Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 35c2690

Browse files
committed
feat: add new solution and format code
1 parent db30b17 commit 35c2690

File tree

51 files changed

+470
-229
lines changed

Some content is hidden

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

51 files changed

+470
-229
lines changed

‎lcof2/剑指 Offer II 034. 外星语言是否排序/Solution.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ function isAlienSorted(words: string[], order: string): boolean {
66
function compare(str1: string, str2: string): boolean {
77
const n = Math.min(str1.length, str2.length);
88
for (let i = 0; i < n; i++) {
9-
let k1 = str1[i], k2 = str2[i];
9+
let k1 = str1[i],
10+
k2 = str2[i];
1011
if (k1 != k2) return charMap.get(k1) < charMap.get(k2);
1112
}
1213
return n == str1.length;
@@ -15,4 +16,4 @@ function isAlienSorted(words: string[], order: string): boolean {
1516
if (!compare(words[i - 1], words[i])) return false;
1617
}
1718
return true;
18-
};
19+
}

‎lcof2/剑指 Offer II 042. 最近请求次数/Solution.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class RecentCounter {
99
ping(t: number): number {
1010
while (this.stack.length && this.stack[0] + 3000 < t) {
1111
this.cnt--;
12-
this.stack.shift()
12+
this.stack.shift();
1313
}
1414
this.cnt++;
1515
this.stack.push(t);
1616
return this.cnt;
1717
}
18-
}
18+
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
function search(nums: number[], target: number): number {
2-
const n = nums.length;
3-
let left = 0,
4-
right = n - 1;
5-
while (left < right) {
6-
const mid = (left + right) >> 1;
7-
if (nums[0] <= nums[mid]) {
8-
if (nums[0] <= target && target <= nums[mid]) {
9-
right = mid;
10-
} else {
11-
left = mid + 1;
12-
}
13-
} else {
14-
if (nums[mid] < target && target <= nums[n - 1]) {
15-
left = mid + 1;
16-
} else {
17-
right = mid;
18-
}
19-
}
20-
}
21-
return nums[left] == target ? left : -1;
22-
}
1+
function search(nums: number[], target: number): number {
2+
const n = nums.length;
3+
let left = 0,
4+
right = n - 1;
5+
while (left < right) {
6+
const mid = (left + right) >> 1;
7+
if (nums[0] <= nums[mid]) {
8+
if (nums[0] <= target && target <= nums[mid]) {
9+
right = mid;
10+
} else {
11+
left = mid + 1;
12+
}
13+
} else {
14+
if (nums[mid] < target && target <= nums[n - 1]) {
15+
left = mid + 1;
16+
} else {
17+
right = mid;
18+
}
19+
}
20+
}
21+
return nums[left] == target ? left : -1;
22+
}

‎solution/0000-0099/0064.Minimum Path Sum/Solution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ function minPathSum(grid: number[][]): number {
1515
}
1616
}
1717
return dp[m - 1][n - 1];
18-
};
18+
}

‎solution/0100-0199/0118.Pascal's Triangle/Solution.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ class Solution:
22
def generate(self, numRows: int) -> List[List[int]]:
33
ans = []
44
for i in range(numRows):
5-
t = [1 if j == 0 or j == i else ans[-1][j] + ans[-1][j - 1]
6-
for j in range(i + 1)]
5+
t = [
6+
1 if j == 0 or j == i else ans[-1][j] + ans[-1][j - 1]
7+
for j in range(i + 1)
8+
]
79
ans.append(t)
810
return ans

‎solution/0100-0199/0130.Surrounded Regions/Solution.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
Do not return anything, modify board in-place instead.
33
*/
4-
function solve(board: string[][]): void {
4+
function solve(board: string[][]): void {
55
function dfs(i, j) {
66
board[i][j] = '.';
77
const dirs = [-1, 0, 1, 0, -1];
@@ -17,7 +17,10 @@
1717
const n = board[0].length;
1818
for (let i = 0; i < m; ++i) {
1919
for (let j = 0; j < n; ++j) {
20-
if ((i == 0 || i == m - 1 || j == 0 || j == n - 1) && board[i][j] == 'O') {
20+
if (
21+
(i == 0 || i == m - 1 || j == 0 || j == n - 1) &&
22+
board[i][j] == 'O'
23+
) {
2124
dfs(i, j);
2225
}
2326
}
@@ -31,4 +34,4 @@
3134
}
3235
}
3336
}
34-
};
37+
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
function findMin(nums: number[]): number {
2-
const n = nums.length;
3-
if (nums[0] <= nums[n - 1]) {
4-
return nums[0];
5-
}
6-
let left = 0,
7-
right = n - 1;
8-
while (left < right) {
9-
const mid = (left + right) >> 1;
10-
if (nums[0] <= nums[mid]) {
11-
left = mid + 1;
12-
} else {
13-
right = mid;
14-
}
15-
}
16-
return nums[left];
17-
}
1+
function findMin(nums: number[]): number {
2+
const n = nums.length;
3+
if (nums[0] <= nums[n - 1]) {
4+
return nums[0];
5+
}
6+
let left = 0,
7+
right = n - 1;
8+
while (left < right) {
9+
const mid = (left + right) >> 1;
10+
if (nums[0] <= nums[mid]) {
11+
left = mid + 1;
12+
} else {
13+
right = mid;
14+
}
15+
}
16+
return nums[left];
17+
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
function findMin(nums: number[]): number {
2-
let left = 0,
3-
right = nums.length - 1;
4-
while (left < right) {
5-
const mid = (left + right) >> 1;
6-
if (nums[mid] > nums[right]) {
7-
left = mid + 1;
8-
} else if (nums[mid] < nums[right]) {
9-
right = mid;
10-
} else {
11-
--right;
12-
}
13-
}
14-
return nums[left];
15-
}
1+
function findMin(nums: number[]): number {
2+
let left = 0,
3+
right = nums.length - 1;
4+
while (left < right) {
5+
const mid = (left + right) >> 1;
6+
if (nums[mid] > nums[right]) {
7+
left = mid + 1;
8+
} else if (nums[mid] < nums[right]) {
9+
right = mid;
10+
} else {
11+
--right;
12+
}
13+
}
14+
return nums[left];
15+
}

‎solution/0200-0299/0208.Implement Trie (Prefix Tree)/Solution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ class Trie {
4343
}
4444
return head;
4545
}
46-
}
46+
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
function hIndex(citations: number[]): number {
2-
const n = citations.length;
3-
let left = 0,
4-
right = n;
5-
while (left < right) {
6-
const mid = (left + right + 1) >> 1;
7-
if (citations[n - mid] >= mid) {
8-
left = mid;
9-
} else {
10-
right = mid - 1;
11-
}
12-
}
13-
return left;
14-
}
1+
function hIndex(citations: number[]): number {
2+
const n = citations.length;
3+
let left = 0,
4+
right = n;
5+
while (left < right) {
6+
const mid = (left + right + 1) >> 1;
7+
if (citations[n - mid] >= mid) {
8+
left = mid;
9+
} else {
10+
right = mid - 1;
11+
}
12+
}
13+
return left;
14+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /