Skip to content

Commit 7cf67d3

Browse files
committed
update the docs
1 parent 28f307b commit 7cf67d3

File tree

5 files changed

+30
-84
lines changed

5 files changed

+30
-84
lines changed

readme.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
# leetcode-typescript
1+
# leetcode-ts
22

3-
Collection of my leetcode prob solution.
3+
Collection of leetcode prob solutions using TypeScript.
44

5-
## How to Run it
5+
## How to use it?
6+
7+
Type "T", in this repo page, and then type the problem title like "best-time-to-buy-and-sell-stock".
8+
9+
And you'll see that file `best-time-to-buy-and-sell-stock.ts` is under the `src/kadanes-algorithm` it's the related topic of this prob, then enter and see the solution, some solution I've added the thinking process as comment.
10+
11+
## How to Run it?
612

713
```
814
$ npm i # install dependency, typescript, ts-node
915
$ npx ts-node src/rotate-array.ts
1016
```
1117

12-
Don't forget to add the test case if you really wanna run it.
13-
14-
Most use case might just reference...
18+
Don't forget to add the test case if you really want to run it!
1519

16-
I would try to sort of by topic (like backtracking / binary search / idk)
20+
Most use-case of this repo might be just a reference.

src/backtracking/surrounded-regions.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,32 @@ function solve(board: string[][]): void {
99

1010
let collection: number[][] = [];
1111
let isBorder = false;
12-
const dfs = (pos: number[]): void => {
13-
const [x, y] = pos;
14-
if (x < 0 || y < 0 || x >= M || y >= N) return;
15-
if (visited[x][y]) return;
16-
if (board[x][y] === "X") return;
12+
const dfs = (i: number, j: number): void => {
13+
if (i < 0 || j < 0 || i >= M || j >= N) return;
14+
if (visited[i][j]) return;
15+
if (board[i][j] === "X") return;
1716

18-
visited[x][y] = true;
19-
collection.push([x, y]);
20-
if (x === 0 || y === 0 || x === M - 1 || y === N - 1) {
17+
visited[i][j] = true;
18+
collection.push([i, j]);
19+
if (i === 0 || j === 0 || i === M - 1 || j === N - 1) {
2120
isBorder = true;
2221
}
23-
dfs([x - 1, y]);
24-
dfs([x + 1, y]);
25-
dfs([x, y - 1]);
26-
dfs([x, y + 1]);
22+
dfs(i - 1, j);
23+
dfs(i + 1, j);
24+
dfs(i, j - 1);
25+
dfs(i, j + 1);
2726
};
2827

2928
for (let i = 0; i < M; i++) {
3029
for (let j = 0; j < N; j++) {
3130
collection = [];
3231
isBorder = false;
33-
dfs([i, j]);
32+
dfs(i, j);
3433
if (isBorder) continue;
35-
for (let col of collection) {
36-
const [x, y] = col;
34+
for (let pos of collection) {
35+
const [x, y] = pos;
3736
board[x][y] = "X";
3837
}
3938
}
4039
}
4140
}
42-
43-
const q = [
44-
["X", "X", "X", "X"],
45-
["X", "O", "O", "X"],
46-
["X", "X", "O", "X"],
47-
["X", "O", "X", "X"],
48-
];
49-
solve(q);
50-
console.log(q);

src/kadanes-algo/best-time-to-buy-and-sell-stock.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/slding-window/contain-duplicate-III.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function containsNearbyAlmostDuplicate(nums: number[], k: number, t: number): bo
1212
const key = getBucketKey(cur);
1313
return (
1414
bucket.has(key) ||
15-
(bucket.has(key + 1) && bucket.get(key + 1) - cur <= t) ||
16-
(bucket.has(key - 1) && cur - bucket.get(key - 1) <= t)
15+
(bucket.has(key + 1) && bucket.get(key + 1)! - cur <= t) ||
16+
(bucket.has(key - 1) && cur - bucket.get(key - 1)! <= t)
1717
);
1818
};
1919

src/trie/implement-trie-prefix-tree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Trie {
1010
const rest = word.substring(1);
1111
if (!this.map.has(first)) this.map.set(first, new Trie());
1212

13-
this.map.get(first).insert(rest);
13+
this.map.get(first)!.insert(rest);
1414
}
1515

1616
search(word: string): boolean {
@@ -20,7 +20,7 @@ class Trie {
2020
const rest = word.substring(1);
2121

2222
if (!this.map.has(first)) return false;
23-
return this.map.get(first).search(rest);
23+
return this.map.get(first)!.search(rest);
2424
}
2525

2626
startsWith(prefix: string): boolean {
@@ -29,7 +29,7 @@ class Trie {
2929
const rest = prefix.substring(1);
3030

3131
if (!this.map.has(first)) return false;
32-
return this.map.get(first).startsWith(rest);
32+
return this.map.get(first)!.startsWith(rest);
3333
}
3434
}
3535

0 commit comments

Comments
 (0)