Skip to content

Commit ca22e0f

Browse files
authored
Improved tasks
1 parent f5e5230 commit ca22e0f

File tree

37 files changed

+106
-85
lines changed

37 files changed

+106
-85
lines changed

src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { ListNode } from '../../com_github_leetcode/listnode'
77

8-
/*
8+
/**
99
* Definition for singly-linked list.
1010
* class ListNode {
1111
* val: number

src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { ListNode } from '../../com_github_leetcode/listnode'
66

7-
/*
7+
/**
88
* Definition for singly-linked list.
99
* class ListNode {
1010
* val: number

src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,26 @@ function findSubstring(s: string, words: string[]): number[] {
66
let n1 = words[0].length
77
let n2 = s.length
88
let map1 = new Map<string, number>()
9-
109
for (let ch of words) {
1110
map1.set(ch, (map1.get(ch) ?? 0) + 1)
1211
}
13-
1412
for (let i = 0; i < n1; i++) {
1513
let left = i
1614
let j = i
1715
let c = 0
1816
let map2 = new Map<string, number>()
19-
2017
while (j + n1 <= n2) {
2118
let word1 = s.substring(j, j + n1)
2219
j += n1
23-
2420
if (map1.has(word1)) {
2521
map2.set(word1, (map2.get(word1) ?? 0) + 1)
2622
c++
27-
2823
while ((map2.get(word1) ?? 0) > (map1.get(word1) ?? 0)) {
2924
let word2 = s.substring(left, left + n1)
3025
map2.set(word2, (map2.get(word2) ?? 0) - 1)
3126
left += n1
3227
c--
3328
}
34-
3529
if (c === words.length) {
3630
ans.push(left)
3731
}

src/main/ts/g0001_0100/s0031_next_permutation/solution.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
*/
77
function nextPermutation(nums: number[]): void {
88
let swapperIndex: number | null = null
9-
109
for (let ind = nums.length - 1; ind >= 0 && swapperIndex == null; ind--) {
1110
if (nums[ind] > nums[ind - 1]) {
1211
swapperIndex = ind - 1
1312
}
1413
}
15-
16-
if (swapperIndex == null) nums.sort((a, b) => a - b)
17-
else {
14+
if (swapperIndex == null) {
15+
nums.sort((a, b) => a - b)
16+
} else {
1817
nums.splice(swapperIndex + 1, nums.length, ...nums.slice(swapperIndex + 1, nums.length).sort((a, b) => a - b))
1918
let indToBringForward = swapperIndex + 1
2019
while (nums[indToBringForward] <= nums[swapperIndex]) ++indToBringForward

src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ function searchRange(nums: number[], target: number): number[] { //NOSONAR
99
let left2 = left1
1010
let right1 = nums.length - 1
1111
let right2 = right1
12-
1312
while (left1 <= right1 || left2 <= right2) {
1413
if (left1 <= right1) {
1514
let mid1 = Math.floor((left1 + right1) / 2)
@@ -22,7 +21,6 @@ function searchRange(nums: number[], target: number): number[] { //NOSONAR
2221
right1 = mid1 - 1
2322
}
2423
}
25-
2624
if (left2 <= right2) {
2725
let mid2 = Math.floor((left2 + right2) / 2)
2826
if (nums[mid2] == target) {

src/main/ts/g0001_0100/s0036_valid_sudoku/solution.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@ function isValidSudoku(board: string[][]): boolean {
55
let rowSet: number[] = new Array(9).fill(0)
66
let colSet: number[] = new Array(9).fill(0)
77
let boxSet: number[] = new Array(9).fill(0)
8-
98
for (let i = 0; i < 9; i++) {
109
for (let j = 0; j < 9; j++) {
1110
if (board[i][j] === '.') {
1211
continue
1312
}
1413
let val = board[i][j].charCodeAt(0) - '0'.charCodeAt(0)
1514
let boxIndex = Math.floor(i / 3) * 3 + Math.floor(j / 3)
16-
1715
if (rowSet[i] & (1 << val) || colSet[j] & (1 << val) || boxSet[boxIndex] & (1 << val)) {
1816
return false
1917
}
20-
2118
rowSet[i] |= 1 << val
2219
colSet[j] |= 1 << val
2320
boxSet[boxIndex] |= 1 << val

src/main/ts/g0001_0100/s0039_combination_sum/solution.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
function combinationSum(candidates: number[], target: number): number[][] {
77
const result: number[][] = []
88
const path: number[] = []
9-
109
const comFunct = (index: number, sum: number) => {
1110
if (sum === target) {
1211
result.push([...path])

src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,24 @@ function spiralOrder(matrix: number[][]): number[] {
88
c = 0
99
let bigR = matrix.length - 1
1010
let bigC = matrix[0].length - 1
11-
1211
while (r <= bigR && c <= bigC) {
1312
for (let i = c; i <= bigC; i++) {
1413
result.push(matrix[r][i])
1514
}
1615
r++
17-
1816
for (let i = r; i <= bigR; i++) {
1917
result.push(matrix[i][bigC])
2018
}
2119
bigC--
22-
2320
for (let i = bigC; i >= c && r <= bigR; i--) {
2421
result.push(matrix[bigR][i])
2522
}
2623
bigR--
27-
2824
for (let i = bigR; i >= r && c <= bigC; i--) {
2925
result.push(matrix[i][c])
3026
}
3127
c++
3228
}
33-
3429
return result
3530
}
3631

src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
// #Big_O_Time_O(n)_Space_O(n) #2025_03_23_Time_0_ms_(100.00%)_Space_56.23_MB_(5.15%)
55

66
function climbStairs(n: number, memo: Record<string, number> = {}): number {
7-
if (n in memo) return memo[n]
8-
if (n === 0) return 1
9-
if (n < 0) return 0
7+
if (n in memo) {
8+
return memo[n]
9+
}
10+
if (n === 0) {
11+
return 1
12+
}
13+
if (n < 0) {
14+
return 0
15+
}
1016
memo[n] = climbStairs(n - 1, memo) + climbStairs(n - 2, memo)
1117
return memo[n]
1218
}

src/main/ts/g0001_0100/s0072_edit_distance/solution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ function minDistance(word1: string, word2: string): number {
88
const l1 = word1.length
99
const l2 = word2.length
1010
const dfs = (w1: number, w2: number): number => {
11-
if (memo[w1][w2] != undefined) return memo[w1][w2]
11+
if (memo[w1][w2] != undefined) {
12+
return memo[w1][w2]
13+
}
1214
if (w1 == l1 && w2 == l2) {
1315
memo[w1][w2] = 0
1416
return 0

0 commit comments

Comments
 (0)