Skip to content

Commit a89efc9

Browse files
committed
docs(readme): all
1 parent fc51bbd commit a89efc9

File tree

24 files changed

+333
-358
lines changed

24 files changed

+333
-358
lines changed

README.md

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,27 @@
1-
# LeetCode Problems
1+
# LeetCode For TypeScript
22

3-
LeetCode problems' solutions with TypeScript
3+
LeetCode problems' submissions & top randed with TypeScript.
4+
5+
**Submissions** was completed by myself.
6+
7+
**Top Randed** includes the best submissions complated by other guys in LeetCode.com with JavaScript.
8+
9+
> Author: Yalda
10+
>
11+
> Github: [leetcode-ts](https://github.com/guocaoyi/leetcode-ts/)
12+
> Blog: [www.yalda.cn](https://www.yalda.cn)
13+
> Online Book: [www.yalda.cn/leetcode-ts](https://www.yalda.cn/leetcode-ts)
414
515
## Topics
616

7-
[Array](./TOPICS.md#array)×100
17+
[Array](./TOPICS.md#array)×100,
818
[Dynamic Programming](./TOPICS.md#string),
919
[Math](./TOPICS.md#),
1020
[String](./TOPICS.md#),
1121
[Tree](./TOPICS.md#),
12-
[Hash Table](./TOPICS.md#),
13-
[Depth-first Search](./TOPICS.md#),
14-
[Binary Search](./TOPICS.md#),
15-
[Tow Pointers](./TOPICS.md#),
16-
[Greedy](./TOPICS.md#),
17-
[Breadth-first Search](./TOPICS.md#),
18-
[Stack](./TOPICS.md#),
19-
[Backtracking](./TOPICS.md#),
20-
[Design](./TOPICS.md#),
21-
[Linked List](./TOPICS.md#),
22-
[Bit Manipulation](./TOPICS.md#),
23-
[Heap](./TOPICS.md#),
24-
[Graph](./TOPICS.md#),
25-
[Sort](./TOPICS.md#),
26-
[Union Find](./TOPICS.md#),
27-
[Divide and Conquer](./TOPICS.md#),
28-
[Binary Search Tree](./TOPICS.md#),
29-
[Trie](./TOPICS.md#),
30-
[Sliding Window](./TOPICS.md#),
31-
[Recursion](./TOPICS.md#),
32-
[Queue](./TOPICS.md#),
33-
[Segment Tree](./TOPICS.md#),
34-
[Minimax](./TOPICS.md#),
35-
[Random](./TOPICS.md#),
36-
[Binary Indexed Tree](./TOPICS.md#),
37-
[Topological Sort](./TOPICS.md#),
38-
[Brainteaser](./TOPICS.md#),
39-
[Geometry](./TOPICS.md#),
40-
[Map](./TOPICS.md#),
41-
[Rejection Sampling](./TOPICS.md#),
42-
[Reservoir Sampling](./TOPICS.md#),
43-
[Memoization](./TOPICS.md#),
4422

4523
## Algorithms
4624

47-
| \# | Title | Topics | Difficulty |
48-
| :-- | :--------------------------------------------- | :--------: | :--------: |
49-
| 1 | Two Sum | String,Map ||
50-
| 2 | Add Tow Numbers | ||
51-
| 3 | Longest Substring Without Repeating Characters | ||
52-
| 4 | Median of Two Sorted Arrays | | ❗❗ |
53-
| 6 | ZigZag Conversion | | ❗❗❗ |
54-
| 14 | Longest Common Prefix | | ❗❗ |
25+
| \# | Title | Topics | Difficulty |
26+
| :--------------------------- | :------ | :--------: | :-------------------------------------: |
27+
| [1](algorithms/0001.Two Sum) | Two Sum | String,Map | {% em color="#5cb85c" %}Easy{% endem %} |

SUMMARY.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Summary
22

3-
- [概览](README.md)
4-
- [Topics](topics.md)
5-
- [0001.Two Sum](./algorithms/0001.Two Sum/README.md)
6-
- [0014.Longest Common Prefix](./algorithms/0014.Longest Common Prefix/README.md)
3+
- [Introduction](README.md)
4+
- [Topics](TOPICS.md)
5+
- [0001.Two Sum](algorithms/0001.Two Sum/README.md)
6+
- [0003.Longest Substring Without Repeating Characters](algorithms/0003.Longest Substring Without Repeating Characters/README.md)
7+
- [0004.Median of Tow Sorted Arrays](algorithms/0004.Median of Tow Sorted Arrays/README.md)
8+
- [0014.Longest Common Prefix](algorithms/0014.Longest Common Prefix/README.md)
9+
- [0017.Letter Combinations of a Phone Number](algorithms/0017.Letter Combinations of a Phone Number/README.md)
10+
- [0074.Search a 2D Matrix](algorithms/0074.Search a 2D Matrix/README.md)
11+
- [0136.Single Number](algorithms/0136.Single Number/README.md)
12+
- [0169.Majority Element](algorithms/0169.Majority Element/README.md)
13+
- [0202.Happy Number](algorithms/0202.Happy Number/README.md)
14+
- [0240.Search a 2D Matrix II](algorithms/0240.Search a 2D Matrix II/README.md)
15+
- [0344.Reverse String](algorithms/0344.Reverse String/README.md)
16+
- [0724.Find Pivot Index](algorithms/0724.Find Pivot Index/README.md)

TOPICS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Related Topics
2+
3+
- Array
4+
- [0014.Longest Common Prefix](algorithms/0014.Longest Common Prefix/README.md)
5+
- [0017.Letter Combinations of a Phone Number](algorithms/0017.Letter Combinations of a Phone Number/README.md)
6+
7+
- String
8+
- [0001.Two Sum](algorithms/0001.Two Sum/README.md)
9+
- [0003.Longest Substring Without Repeating Characters](algorithms/0003.Longest Substring Without Repeating Characters/README.md)
10+
- [0074.Search a 2D Matrix](algorithms/0074.Search a 2D Matrix/README.md)

algorithms/0001.Two Sum/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# 1. Two Sum
22

3-
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
3+
Given an array of integers, return **indices** of the two numbers such that they add up to a specific target.
44

5-
You may assume that each input would have exactly one solution, and you may not use the same element twice.
5+
You may assume that each input would have **exactly** one solution, and you may not use the same element twice.
66

7-
**Example:**
7+
## Example
88

9-
```txt
9+
```bash
1010
Given nums = [2, 7, 11, 15], target = 9,
1111

1212
Because nums[0] + nums[1] = 2 + 7 = 9,
1313
return [0, 1].
1414
```
1515

16-
## 解析
16+
## Related Topics
17+
18+
- Array
19+
- Hash Table

algorithms/0001.Two Sum/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ var twoSum = (nums: number[], target: number): number[] => {
5858
}
5959
};
6060

61-
6261
/**
6362
* 哈希遍历
6463
* @top
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 3. Longest Substring Without Repeating Characters
2+
3+
Given a string, find the length of the **longest substring** without repeating characters.
4+
5+
## Example
6+
7+
```bash
8+
Input: "abcabcbb"
9+
Output: 3
10+
Explanation: The answer is "abc", with the length of 3.
11+
```
12+
13+
```bash
14+
Input: "bbbbb"
15+
Output: 1
16+
Explanation: The answer is "b", with the length of 1.
17+
```
18+
19+
```bash
20+
Input: "pwwkew"
21+
Output: 3
22+
Explanation: The answer is "wke", with the length of 3.
23+
Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
24+
```
25+
26+
## Related Topics
27+
28+
- Hash Table
29+
- Two Pointers
30+
- String
31+
- Sliding Window
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 4. Median of Tow Sorted Arrays
2+
3+
There are two sorted arrays **nums1** and **nums2** of size m and n respectively.
4+
5+
Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
6+
7+
You may assume **nums1** and **nums2** cannot be both empty.
8+
9+
## Example
10+
11+
```bash
12+
nums1 = [1, 3]
13+
nums2 = [2]
14+
15+
The median is 2.0
16+
```
17+
18+
```bash
19+
nums1 = [1, 2]
20+
nums2 = [3, 4]
21+
22+
The median is (2 + 3)/2 = 2.5
23+
```
24+
25+
## Related Topics
26+
27+
- Array
28+
- Binary Search
29+
- Divide and Conquer

algorithms/0004.Median of Tow Sorted Arrays/index.ts

Whitespace-only changes.
Lines changed: 4 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
# 14 Longest Common Prefix
2-
3-
## Related Topics
4-
5-
- String
6-
7-
## Description
1+
# 14. Longest Common Prefix
82

93
Write a function to find the longest common prefix string amongst an array of strings.
104

11-
If there is no common prefix, return an empty string "".
5+
If there is no common prefix, return an empty string `""`.
126

137
## Example
148

@@ -27,96 +21,6 @@ Explanation: There is no common prefix among the input strings.
2721

2822
All given inputs are in lowercase letters a-z.
2923

30-
## Thinking
31-
32-
- \*\*
33-
34-
## Submissions
35-
36-
### I: 循环遍历
37-
38-
刚拿到这题没有细想,认为这题比较简单;直接使用循环遍历的方式一遍一遍顺序访问数组。当子字符串不相等时 Break,结果却超时了。简单了分析了原因在长数组的情况下,过多的进行了顺序访问,实践复杂度为 O(k\*n)。便放弃广度优先,改为深读优先。后面发现,是长度为 1 的数组进入了死循环。
39-
40-
- Status: Time Limit Exceeded
41-
- Last executed input: : `[""]`
42-
43-
```typescript
44-
var longestCommonPrefix = function(strs: string[]) {
45-
let prefix: string = "";
46-
if (strs && strs.length > 0) {
47-
let point = 1;
48-
while (true) {
49-
prefix = strs[0].slice(0, point);
50-
for (let i = 0; i < strs.length; i++) {
51-
if (prefix !== strs[i].slice(0, point)) {
52-
return prefix.slice(0, prefix.length - 1);
53-
}
54-
}
55-
point++;
56-
}
57-
} else {
58-
return "";
59-
}
60-
};
61-
```
62-
63-
### II: 单次遍历
64-
65-
没有兼容好空字符串的问题(PS:条件不是 a-z 么?WTF?)
66-
67-
- Status: Time Limit Exceeded
68-
- Last executed input: : `["",""]`
69-
70-
```typescript
71-
var longestCommonPrefix = function(strs: string[]) {
72-
let prefix: string = "";
73-
if (strs.length == 1) {
74-
return strs[0];
75-
} else if (strs.length > 1) {
76-
let point = 1;
77-
while (true) {
78-
prefix = strs[0].slice(0, point);
79-
for (let i = 0; i < strs.length; i++) {
80-
if (prefix !== strs[i].slice(0, point)) {
81-
return prefix.slice(0, prefix.length - 1);
82-
}
83-
}
84-
point++;
85-
}
86-
return "";
87-
} else {
88-
return "";
89-
}
90-
};
91-
```
92-
93-
### III: 单次遍历
94-
95-
使用 `strs[0]` 作为初始前缀串,逐一遍历 `strs[]` 元素进行比较,如 `String.indexOf !== 0` 则自减长度 1,直至成立后继续访问后面的元素。
96-
97-
- Status: Accepted
98-
- Runtime: 60ms > 92.74%
99-
- Memory: 33.8MB < 86.74%
100-
101-
```typescript
102-
var longestCommonPrefix = (strs: string[]) => {
103-
if (strs && strs.length > 0) {
104-
let prefix: string = strs[0]; // 使用 strs[0] 作为初始前缀串
105-
for (let i = 1; i < strs.length; i++) {
106-
let subStr = strs[i];
107-
while (subStr.indexOf(prefix) !== 0) {
108-
// 不存在前缀子串
109-
prefix = prefix.slice(0, prefix.length - 1);
110-
if (prefix.length == 0) {
111-
return "";
112-
}
113-
}
114-
}
115-
return prefix;
116-
} else {
117-
return "";
118-
}
119-
};
120-
```
24+
## Related Topics
12125

122-
## Top Ranked
26+
- String

algorithms/0014.Longest Common Prefix/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var longestCommonPrefix = function(strs: string[]) {
4343
}
4444
point++;
4545
}
46-
return "";
4746
} else {
4847
return "";
4948
}
@@ -53,7 +52,7 @@ var longestCommonPrefix = function(strs: string[]) {
5352
* 单次遍历
5453
* @description 使用 `strs[0]` 作为初始前缀串,逐一遍历 `strs[]` 元素进行比较,如 `String.indexOf !== 0` 则自减长度 1,直至成立后继续访问后面的元素。
5554
* @status Accepted
56-
* @runtime 60ms > 92.74%
55+
* @runtime 60ms < 92.74%
5756
* @memory 33.8MB < 86.74%
5857
*/
5958
var longestCommonPrefix = (strs: string[]) => {

0 commit comments

Comments
 (0)