Skip to content

Commit 24ae5ab

Browse files
committed
Improved tasks
1 parent 01eaf60 commit 24ae5ab

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/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You may assume the two numbers do not contain any leading zero, except the numbe
4242
```typescript
4343
import { ListNode } from '../../com_github_leetcode/listnode'
4444

45-
/*
45+
/**
4646
* Definition for singly-linked list.
4747
* class ListNode {
4848
* val: number

src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ _Merge all the linked-lists into one sorted linked-list and return it._
4343
```typescript
4444
import { ListNode } from '../../com_github_leetcode/listnode'
4545

46-
/*
46+
/**
4747
* Definition for singly-linked list.
4848
* class ListNode {
4949
* val: number

src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/readme.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,26 @@ function findSubstring(s: string, words: string[]): number[] {
4545
let n1 = words[0].length
4646
let n2 = s.length
4747
let map1 = new Map<string, number>()
48-
4948
for (let ch of words) {
5049
map1.set(ch, (map1.get(ch) ?? 0) + 1)
5150
}
52-
5351
for (let i = 0; i < n1; i++) {
5452
let left = i
5553
let j = i
5654
let c = 0
5755
let map2 = new Map<string, number>()
58-
5956
while (j + n1 <= n2) {
6057
let word1 = s.substring(j, j + n1)
6158
j += n1
62-
6359
if (map1.has(word1)) {
6460
map2.set(word1, (map2.get(word1) ?? 0) + 1)
6561
c++
66-
6762
while ((map2.get(word1) ?? 0) > (map1.get(word1) ?? 0)) {
6863
let word2 = s.substring(left, left + n1)
6964
map2.set(word2, (map2.get(word2) ?? 0) - 1)
7065
left += n1
7166
c--
7267
}
73-
7468
if (c === words.length) {
7569
ans.push(left)
7670
}

src/main/ts/g0001_0100/s0031_next_permutation/readme.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ The replacement must be **[in place](http://en.wikipedia.org/wiki/In-place_algor
5050
*/
5151
function nextPermutation(nums: number[]): void {
5252
let swapperIndex: number | null = null
53-
5453
for (let ind = nums.length - 1; ind >= 0 && swapperIndex == null; ind--) {
5554
if (nums[ind] > nums[ind - 1]) {
5655
swapperIndex = ind - 1
5756
}
5857
}
59-
60-
if (swapperIndex == null) nums.sort((a, b) => a - b)
61-
else {
58+
if (swapperIndex == null) {
59+
nums.sort((a, b) => a - b)
60+
} else {
6261
nums.splice(swapperIndex + 1, nums.length, ...nums.slice(swapperIndex + 1, nums.length).sort((a, b) => a - b))
6362
let indToBringForward = swapperIndex + 1
6463
while (nums[indToBringForward] <= nums[swapperIndex]) ++indToBringForward

src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function searchRange(nums: number[], target: number): number[] { //NOSONAR
4646
let left2 = left1
4747
let right1 = nums.length - 1
4848
let right2 = right1
49-
5049
while (left1 <= right1 || left2 <= right2) {
5150
if (left1 <= right1) {
5251
let mid1 = Math.floor((left1 + right1) / 2)
@@ -59,7 +58,6 @@ function searchRange(nums: number[], target: number): number[] { //NOSONAR
5958
right1 = mid1 - 1
6059
}
6160
}
62-
6361
if (left2 <= right2) {
6462
let mid2 = Math.floor((left2 + right2) / 2)
6563
if (nums[mid2] == target) {

src/main/ts/g0001_0100/s0036_valid_sudoku/readme.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,16 @@ function isValidSudoku(board: string[][]): boolean {
6767
let rowSet: number[] = new Array(9).fill(0)
6868
let colSet: number[] = new Array(9).fill(0)
6969
let boxSet: number[] = new Array(9).fill(0)
70-
7170
for (let i = 0; i < 9; i++) {
7271
for (let j = 0; j < 9; j++) {
7372
if (board[i][j] === '.') {
7473
continue
7574
}
7675
let val = board[i][j].charCodeAt(0) - '0'.charCodeAt(0)
7776
let boxIndex = Math.floor(i / 3) * 3 + Math.floor(j / 3)
78-
7977
if (rowSet[i] & (1 << val) || colSet[j] & (1 << val) || boxSet[boxIndex] & (1 << val)) {
8078
return false
8179
}
82-
8380
rowSet[i] |= 1 << val
8481
colSet[j] |= 1 << val
8582
boxSet[boxIndex] |= 1 << val

src/main/ts/g0001_0100/s0039_combination_sum/readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ It is **guaranteed** that the number of unique combinations that sum up to `targ
6060
function combinationSum(candidates: number[], target: number): number[][] {
6161
const result: number[][] = []
6262
const path: number[] = []
63-
6463
const comFunct = (index: number, sum: number) => {
6564
if (sum === target) {
6665
result.push([...path])

src/main/ts/g0001_0100/s0054_spiral_matrix/readme.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,24 @@ function spiralOrder(matrix: number[][]): number[] {
3939
c = 0
4040
let bigR = matrix.length - 1
4141
let bigC = matrix[0].length - 1
42-
4342
while (r <= bigR && c <= bigC) {
4443
for (let i = c; i <= bigC; i++) {
4544
result.push(matrix[r][i])
4645
}
4746
r++
48-
4947
for (let i = r; i <= bigR; i++) {
5048
result.push(matrix[i][bigC])
5149
}
5250
bigC--
53-
5451
for (let i = bigC; i >= c && r <= bigR; i--) {
5552
result.push(matrix[bigR][i])
5653
}
5754
bigR--
58-
5955
for (let i = bigR; i >= r && c <= bigC; i--) {
6056
result.push(matrix[i][c])
6157
}
6258
c++
6359
}
64-
6560
return result
6661
}
6762

src/main/ts/g0001_0100/s0070_climbing_stairs/readme.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ Each time you can either climb `1` or `2` steps. In how many distinct ways can y
3333

3434
```typescript
3535
function climbStairs(n: number, memo: Record<string, number> = {}): number {
36-
if (n in memo) return memo[n]
37-
if (n === 0) return 1
38-
if (n < 0) return 0
36+
if (n in memo) {
37+
return memo[n]
38+
}
39+
if (n === 0) {
40+
return 1
41+
}
42+
if (n < 0) {
43+
return 0
44+
}
3945
memo[n] = climbStairs(n - 1, memo) + climbStairs(n - 2, memo)
4046
return memo[n]
4147
}

src/main/ts/g0001_0100/s0072_edit_distance/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function minDistance(word1: string, word2: string): number {
4242
const l1 = word1.length
4343
const l2 = word2.length
4444
const dfs = (w1: number, w2: number): number => {
45-
if (memo[w1][w2] != undefined) return memo[w1][w2]
45+
if (memo[w1][w2] != undefined) {
46+
return memo[w1][w2]
47+
}
4648
if (w1 == l1 && w2 == l2) {
4749
memo[w1][w2] = 0
4850
return 0

0 commit comments

Comments
 (0)