Skip to content

Commit 7ab8060

Browse files
committed
feat: update some description
1 parent 4613341 commit 7ab8060

Some content is hidden

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

44 files changed

+346
-135
lines changed

README.md

+59-59
Original file line numberDiff line numberDiff line change
@@ -26,73 +26,73 @@
2626

2727
## Easy
2828

29-
|#|Title|Tag|
30-
|:------------- |:------------- |:------------- |
31-
|1|[Two Sum][001]|Array, Hash Table|
32-
|7|[Reverse Integer][007]|Math|
33-
|9|[Palindrome Number][009]|Math|
34-
|13|[Roman to Integer][013]|Math, String|
35-
|14|[Longest Common Prefix][014]|String|
36-
|20|[Valid Parentheses][020]|Stack, String|
37-
|21|[Merge Two Sorted Lists][021]|Linked List|
38-
|26|[Remove Duplicates from Sorted Array][026]|Array, Two Pointers|
39-
|27|[Remove Element][027]|Array, Two Pointers|
40-
|28|[Implement strStr()][028]|Two Pointers, String|
41-
|35|[Search Insert Position][035]|String|
42-
|38|[Count and Say][038]|String|
43-
|53|[Maximum Subarray][053]|Array, Dynamic Programming, Divide and Conquer|
44-
|58|[Length of Last Word][058]|String|
45-
|66|[Plus One][066]|Array, Math|
46-
|67|[Add Binary][067]|Math, String|
47-
|69|[Sqrt(x)][069]|Binary Search, Math|
48-
|70|[Climbing Stairs][070]|Dynamic Programming|
49-
|83|[Remove Duplicates from Sorted List][083]|Linked List|
50-
|88|[Merge Sorted Array][088]|Array, Two Pointers|
51-
|100|[Same Tree][100]|Tree, Depth-first Search|
52-
|101|[Symmetric Tree][101]|Tree, Depth-first Search, Breadth-first Search|
53-
|104|[Maximum Depth of Binary Tree][104]|Tree, Depth-first Search|
54-
|107|[Binary Tree Level Order Traversal II][107]|Tree, Breadth-first Search|
55-
|108|[Convert Sorted Array to Binary Search Tree][108]|Tree, Depth-first Search|
56-
|110|[Balanced Binary Tree][110]|Tree, Depth-first Search|
57-
|111|[Minimum Depth of Binary Tree][111]|Tree, Depth-first Search, Breadth-first Search|
58-
|112|[Path Sum][112]|Tree, Depth-first Search|
59-
|118|[Pascal's Triangle][118]|Array|
60-
|119|[Pascal's Triangle II][119]|Array|
61-
|121|[Best Time to Buy and Sell Stock][121]|Array, Dynamic Programmin|
62-
|122|[Best Time to Buy and Sell Stock II][122]|Array, Greedy|
63-
|543|[Diameter of Binary Tree][543]|Tree|
29+
| # | Title | Tag |
30+
| :--- | :--------------------------------------- | :--------------------------------------- |
31+
| 1 | [Two Sum][001] | Array, Hash Table |
32+
| 7 | [Reverse Integer][007] | Math |
33+
| 9 | [Palindrome Number][009] | Math |
34+
| 13 | [Roman to Integer][013] | Math, String |
35+
| 14 | [Longest Common Prefix][014] | String |
36+
| 20 | [Valid Parentheses][020] | Stack, String |
37+
| 21 | [Merge Two Sorted Lists][021] | Linked List |
38+
| 26 | [Remove Duplicates from Sorted Array][026] | Array, Two Pointers |
39+
| 27 | [Remove Element][027] | Array, Two Pointers |
40+
| 28 | [Implement strStr()][028] | Two Pointers, String |
41+
| 35 | [Search Insert Position][035] | String |
42+
| 38 | [Count and Say][038] | String |
43+
| 53 | [Maximum Subarray][053] | Array, Divide and Conquer, Dynamic Programming |
44+
| 58 | [Length of Last Word][058] | String |
45+
| 66 | [Plus One][066] | Array, Math |
46+
| 67 | [Add Binary][067] | Math, String |
47+
| 69 | [Sqrt(x)][069] | Binary Search, Math |
48+
| 70 | [Climbing Stairs][070] | Dynamic Programming |
49+
| 83 | [Remove Duplicates from Sorted List][083] | Linked List |
50+
| 88 | [Merge Sorted Array][088] | Array, Two Pointers |
51+
| 100 | [Same Tree][100] | Tree, Depth-first Search |
52+
| 101 | [Symmetric Tree][101] | Tree, Depth-first Search, Breadth-first Search |
53+
| 104 | [Maximum Depth of Binary Tree][104] | Tree, Depth-first Search |
54+
| 107 | [Binary Tree Level Order Traversal II][107] | Tree, Breadth-first Search |
55+
| 108 | [Convert Sorted Array to Binary Search Tree][108] | Tree, Depth-first Search |
56+
| 110 | [Balanced Binary Tree][110] | Tree, Depth-first Search |
57+
| 111 | [Minimum Depth of Binary Tree][111] | Tree, Depth-first Search, Breadth-first Search |
58+
| 112 | [Path Sum][112] | Tree, Depth-first Search |
59+
| 118 | [Pascal's Triangle][118] | Array |
60+
| 119 | [Pascal's Triangle II][119] | Array |
61+
| 121 | [Best Time to Buy and Sell Stock][121] | Array, Dynamic Programmin |
62+
| 122 | [Best Time to Buy and Sell Stock II][122] | Array, Greedy |
63+
| 543 | [Diameter of Binary Tree][543] | Tree |
6464

6565

6666
## Medium
6767

68-
|#|Title|Tag|
69-
|:------------- |:------------- |:------------- |
70-
|2|[Add Two Numbers][002]|Linked List, Math|
71-
|3|[Longest Substring Without Repeating Characters][003]|Hash Table, Two Pointers, String|
72-
|5|[Longest Palindromic Substring][005]|String|
73-
|8|[String to Integer (atoi)][008]|Math, String|
74-
|15|[3Sum][015]|Array, Two Pointers|
75-
|17|[Letter Combinations of a Phone Number][017]|String, Backtracking|
76-
|19|[Remove Nth Node From End of List][019]|Linked List, Two Pointers|
77-
|33|[Search in Rotated Sorted Array][033]|Arrays, Binary Search|
78-
|43|[Multiply Strings][043]|Math, String|
79-
|49|[Group Anagrams][049]|Hash Table, String|
80-
|50|[Pow(x, n)][050]|Math, Binary Search|
81-
|56|[Merge Intervals][056]|Array, Sort|
82-
|554|[Brick Wall][554]|Hash Table|
68+
| # | Title | Tag |
69+
| :--- | :--------------------------------------- | :------------------------------- |
70+
| 2 | [Add Two Numbers][002] | Linked List, Math |
71+
| 3 | [Longest Substring Without Repeating Characters][003] | Hash Table, Two Pointers, String |
72+
| 5 | [Longest Palindromic Substring][005] | String |
73+
| 8 | [String to Integer (atoi)][008] | Math, String |
74+
| 15 | [3Sum][015] | Array, Two Pointers |
75+
| 17 | [Letter Combinations of a Phone Number][017] | String, Backtracking |
76+
| 19 | [Remove Nth Node From End of List][019] | Linked List, Two Pointers |
77+
| 33 | [Search in Rotated Sorted Array][033] | Arrays, Binary Search |
78+
| 43 | [Multiply Strings][043] | Math, String |
79+
| 49 | [Group Anagrams][049] | Hash Table, String |
80+
| 50 | [Pow(x, n)][050] | Math, Binary Search |
81+
| 56 | [Merge Intervals][056] | Array, Sort |
82+
| 554 | [Brick Wall][554] | Hash Table |
8383

8484

8585
## Hard
8686

87-
|#|Title|Tag|
88-
|:------------- |:------------- |:------------- |
89-
|4|[Median of Two Sorted Arrays][004]|Array, Binary Search, Divide and Conquer|
90-
|10|[Regular Expression Matching][010]|String, Dynamic Programming, Backtracking|
91-
|23|[Merge k Sorted Lists][023]|Linked List, Divide and Conquer, Heap|
92-
|25|[Reverse Nodes in k-Group][025]|Linked List|
93-
|44|[Reverse Nodes in k-Group][044]|String, Dynamic Programming, Backtracking, Greedy|
94-
|57|[Insert Interval][057]|Array, Sort|
95-
|68|[Text Justification][068]|String|
87+
| # | Title | Tag |
88+
| :--- | :--------------------------------- | :--------------------------------------- |
89+
| 4 | [Median of Two Sorted Arrays][004] | Array, Binary Search, Divide and Conquer |
90+
| 10 | [Regular Expression Matching][010] | String, Dynamic Programming, Backtracking |
91+
| 23 | [Merge k Sorted Lists][023] | Linked List, Divide and Conquer, Heap |
92+
| 25 | [Reverse Nodes in k-Group][025] | Linked List |
93+
| 44 | [Wildcard Matching][044] | String, Dynamic Programming, Backtracking, Greedy |
94+
| 57 | [Insert Interval][057] | Array, Sort |
95+
| 68 | [Text Justification][068] | String |
9696

9797

9898

note/002/README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
## Description
44

5-
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
5+
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order** and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
66

77
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
88

9-
**Input:** (2 -> 4 -> 3) + (5 -> 6 -> 4)
10-
**Output:** 7 -> 0 -> 8
9+
**Example**
10+
11+
```
12+
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
13+
Output: 7 -> 0 -> 8
14+
Explanation: 342 + 465 = 807.
15+
```
1116

1217
**Tags:** Linked List, Math
1318

note/003/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Given `"abcabcbb"`, the answer is `"abc"`, which the length is 3.
1010

1111
Given `"bbbbb"`, the answer is `"b"`, with the length of 1.
1212

13-
Given `"pwwkew"`, the answer is `"wke"`, with the length of 3. Note that the answer must be a **substring**, `"pwke"` is a *subsequence*and not a substring.
13+
Given `"pwwkew"`, the answer is `"wke"`, with the length of 3. Note that the answer must be a **substring**, `"pwke"` is a *subsequence* and not a substring.
1414

1515
**Tags:** Hash Table, Two Pointers, String
1616

note/004/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ nums1 = [1, 3]
1313
nums2 = [2]
1414
1515
The median is 2.0
16-
1716
```
1817

1918
**Example 2:**

note/005/README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Input: "babad"
1212
Output: "bab"
1313
1414
Note: "aba" is also a valid answer.
15-
1615
```
1716

1817
**Example:**
@@ -64,8 +63,10 @@ class Solution {
6463
如果利用暴力法遍历所有字串是否回文的情况这道题肯定是 `Time Limit Exceeded` 的,那么我们是否可以把之前遍历的结果利用上呢,那么动态规划的想法就呼之欲出了,我们定义 `dp[i][j]` 的意思为字符串区间`[i, j]`是否为回文串,那么我们分三种情况:
6564

6665
1.`i == j` 时,那么毫无疑问 `dp[i][j] = true`
66+
6767
2.`i + 1 == j` 时,那么 `dp[i][j]` 的值取决于 `s[i] == s[j]`
68-
3.`i + 1 < j` 时,那么 `dp[i][j]` 的值取决于 `dp[i + 1][j - 1] && s[i] == s[j]`
68+
69+
3.`i + 1 < j` 时,那么 `dp[i][j]` 的值取决于 `dp[i + 1][j - 1] && s[i] == s[j]`
6970

7071
根据以上的动态转移方程,我们的问题即可迎刃而解,时间复杂度的话显而易见,也是 `O(n^2)`
7172

@@ -101,12 +102,14 @@ class Solution {
101102

102103
马拉车算法(Manacher's Algorithm)
103104

104-
## 背景
105+
### 背景
105106

106107
给定一个字符串,求出其最长回文子串(回文字符串就是从左到右读和从右往左读完全一样,也就是字符串关于中间对称)。例如:
107108

108109
1. s = "babad",最长回文长度为 `3`,可以是 `bab` 或者 `aba`
110+
109111
2. s = "cbbda",最长回文长度为 `2`,即 `bb`
112+
110113
3. s = "abcde",最长回文长度为 `1`,即单个字符本身。
111114

112115
这个问题等同于LeetCode上的 [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring),其相关题解可以查看这里:[传送门](https://github.com/Blankj/awesome-java-leetcode/blob/master/note/005/README.md)
@@ -116,7 +119,7 @@ class Solution {
116119
1975年,一个叫 Manacher 的人发明了 Manacher 算法(中文名:马拉车算法),该算法可以把时间复杂度提升到 `O(n)`,下面我以我理解的思路来讲解其原理。
117120

118121

119-
## 分析
122+
### 分析
120123

121124
由于回文串的奇偶行不确定,比如 `lol` 是奇回文,而 `lool` 是偶回文,马拉车算法的第一步就是对其进行预处理,做法就是在每个字符两侧都加上一个特殊字符,一般就是不会出现在原串中的即可,我们可以选取 `#`,那么
122125

note/007/README.md

+17-12
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,32 @@
22

33
## Description
44

5-
Reverse digits of an integer.
5+
Given a 32-bit signed integer, reverse digits of an integer.
66

7-
**Example1:** x = 123, return 321
7+
**Example 1:**
88

9-
**Example2:** x = -123, return -321
10-
11-
**Spoilers:**
12-
13-
**Have you thought about this?**
9+
```
10+
Input: 123
11+
Output: 321
12+
```
1413

15-
Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!
14+
**Example 2:**
1615

17-
If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
16+
```
17+
Input: -123
18+
Output: -321
19+
```
1820

19-
Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?
21+
**Example 3:**
2022

21-
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
23+
```
24+
Input: 120
25+
Output: 21
26+
```
2227

2328
**Note:**
2429

25-
The input is assumed to be a 32-bit signed integer. Your function should **return 0 when the reversed integer overflows**.
30+
Assume we are dealing with an environment which could only hold integers within the 32-bit signed integer range. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
2631

2732
**Tags:** Math
2833

note/010/README.md

+19-11
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ isMatch("aab", "c*a*b") → true
2929
## 思路0
3030

3131
题意是让让你从判断`s`字符串是否正则匹配于`p`,这道题和[Wildcard Matching][044]很是相似,区别在于`*`,通配符的`*`是可以随意出现的,跟前面字符没有任何关系,其作用是可以表示任意字符串;而正则匹配的`*`不能单独存在,前面必须具有一个字符,其意义是表明前面的这个字符个数可以是任意个数,包括0个。首先我们用递归的方式来实现,其思路如下:
32-
* 如果`s``p`都为空,那么返回`true`
33-
* 如果`p`的长度为1,当`s`的长度也为1,并且他们首位匹配则返回`true`,否则返回`false`
34-
* 如果`p`的第二个字符不为'*',如果`s`为空,那就返回`false`,首位匹配则返回递归调用他们去掉首位的子字符串,否则返回`false`
35-
* 如果`p`的第二个字符为'*',循环当`s`不为空,且首位匹配,如果递归调用是否匹配`s`字符串和`p`去掉前两位的子字符串,则返回`true`,否则`s`去掉首字母继续循环
36-
* 返回递归调用`s`字符串和`p`去掉前两位的子字符串是否匹配
32+
33+
* 如果`s``p`都为空,那么返回`true`
34+
35+
* 如果`p`的长度为1,当`s`的长度也为1,并且他们首位匹配则返回`true`,否则返回`false`
36+
37+
* 如果`p`的第二个字符不为 '*',如果`s`为空,那就返回`false`,首位匹配则返回递归调用他们去掉首位的子字符串,否则返回`false`
38+
39+
* 如果`p`的第二个字符为 '*',循环当`s`不为空,且首位匹配,如果递归调用是否匹配`s`字符串和`p`去掉前两位的子字符串,则返回`true`,否则`s`去掉首字母继续循环;
40+
41+
* 返回递归调用`s`字符串和`p`去掉前两位的子字符串是否匹配。
3742

3843
```java
3944
class Solution {
@@ -61,10 +66,13 @@ class Solution {
6166

6267
## 思路1
6368

64-
我们可以把上面的思路更简单化,如下
65-
* 如果`s``p`都为空,那么返回`true`
66-
* 如果`p`的第二个字符为`*`,由于`*`前面的字符个数可以为任意,那么我们先递归调用个数为0的情况;或者当`s`不为空,如果他们的首字母匹配,那么我们就递归调用去掉去掉首字母的`s`和完整的`p`
67-
* 如果`p`的第二个字符不为`*`,那么我们就老老实实判断第一个字符是否匹配并且递归调用他们去掉首位的子字符串
69+
我们可以把上面的思路更简单化,如下:
70+
71+
* 如果`s``p`都为空,那么返回`true`
72+
73+
* 如果`p`的第二个字符为`*`,由于`*`前面的字符个数可以为任意,那么我们先递归调用个数为0的情况;或者当`s`不为空,如果他们的首字母匹配,那么我们就递归调用去掉去掉首字母的`s`和完整的`p`
74+
75+
* 如果`p`的第二个字符不为`*`,那么我们就老老实实判断第一个字符是否匹配并且递归调用他们去掉首位的子字符串。
6876

6977
```java
7078
class Solution {
@@ -84,10 +92,10 @@ class Solution {
8492
## 思路2
8593

8694
另一种思路就是动态规划了,我们定义`dp[i][j]`的真假来表示`s[0..i)`是否匹配`p[0..j)`,通过思路1,我们可以确定其状态转移方程如下所示:
87-
* 如果`p[j - 1] == '*'`, `dp[i][j] = dp[i][j - 2] || (pc[j - 2] == sc[i - 1] || pc[j - 2] == '.') && dp[i - 1][j];`
88-
* 如果`p[j - 1] != '*'``dp[i][j] = dp[i - 1][j - 1] && (pc[j - 1] == '.' || pc[j - 1] == sc[i - 1]);`
8995

96+
* 如果`p[j - 1] == '*'`, `dp[i][j] = dp[i][j - 2] || (pc[j - 2] == sc[i - 1] || pc[j - 2] == '.') && dp[i - 1][j];`
9097

98+
* 如果`p[j - 1] != '*'``dp[i][j] = dp[i - 1][j - 1] && (pc[j - 1] == '.' || pc[j - 1] == sc[i - 1]);`
9199

92100
```java
93101
class Solution {

note/013/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Input is guaranteed to be within the range from 1 to 3999.
1111

1212
## 思路
1313

14-
题意是罗马数字转整型数,范围从1到3999,查看下百度百科的罗马数字介绍如下
14+
题意是罗马数字转整型数,范围从1到3999,查看下百度百科的罗马数字介绍如下
1515

1616
* 相同的数字连写,所表示的数等于这些数字相加得到的数,如 Ⅲ=3;
17+
1718
* 小的数字在大的数字的右边,所表示的数等于这些数字相加得到的数,如 Ⅷ=8、Ⅻ=12;
18-
* 小的数字(限于 Ⅰ、X 和 C)在大的数字的左边,所表示的数等于大数减小数得到的数,如 Ⅳ=4、Ⅸ=9;
19+
20+
* 小的数字(限于 Ⅰ、X 和 C)在大的数字的左边,所表示的数等于大数减小数得到的数,如 Ⅳ=4、Ⅸ=9。
1921

2022
那么我们可以利用map来完成罗马数字的7个数字符号:I、V、X、L、C、D、M和整数的映射关系,然后根据上面的解释来模拟完成即可。
2123

note/017/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
1414
```
1515

1616
**Note:**
17+
1718
Although the above answer is in lexicographical order, your answer could be in any order you want.
1819

1920
**Tags:** String, Backtracking

note/021/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
66

7+
**Example:**
8+
9+
```
10+
Input: 1->2->4, 1->3->4
11+
Output: 1->1->2->3->4->4
12+
```
13+
714
**Tags:** Linked List
815

916

note/023/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Description
44

5-
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
5+
Merge *k* sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
66

77
**Tags:** Linked List, Divide and Conquer, Heap
88

0 commit comments

Comments
 (0)