Skip to content

Commit ceeaa1d

Browse files
author
lucifer
committed
2 parents f78749d + 266c14b commit ceeaa1d

9 files changed

+41
-7
lines changed

README.en.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ The data structures mainly include:
139139
- [String Problems](./thinkings/string-problems-en.md)
140140
- [Sliding Window Technique](./thinkings/slide-window.en.md)
141141
- [Union Find](./thinkings/union-find.en.md) 🆕
142+
- [Trie](./thinkings/trie.en.md) 🆕
142143

143144
### Anki Flashcards
144145

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="app.diagrams.net" modified="2020-07-14T05:44:32.784Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" etag="spOGC2PEA06TpGs6OMPO" version="13.4.2" type="device"><diagram id="zUBkOizd3lOV14bIgwrr" name="Page-1">7Ztdj6M2FIZ/TS4bgc1HcjlJN7sXXXWrqTSXKy92AlqDqe1sMv31tYMhgMkOVQlEHRJpEr824HkfsA/HZAG36fkjR3n8mWFCF8DB5wX8dQHA2nfVXy28FoIXrgvhwBNcSO5VeE7+JkZ0jHpMMBGNhpIxKpO8KUYsy0gkGxrinJ2azfaMNo+aowOxhOcIUVt9SbCMC3XlO1f9E0kOcXlk1zE1KSobG0HECLNTTYIfFnDLGZPFt/S8JVR7V/pSbLe7UVt1jJNM9tngS/r8SYT+6Y/Njx14kfj3z3j1Cyj28gPRo/mHTWfla+mA2osyWxU2pziR5DlHka45KdxKi2VKVclVX5HICwL75EzUQTdm34RLcr7ZabeyQp1ChKVE8lfVxGzgrY175vRxA1M+XWGUUlzjUGrI4D9Ue746pL4Yk/6FYdAyDD2YY6DpGPAmdsyzHMsfyzEYNB2D7sSO+Q/vmNtybDWxY4HlGH0wx8KmY97U41hoOUYezLHWOObDiR1bvT1VVlO8ozzASMTajEuhZpaQnH0nW0YZV0rGMm0wRd8I/cJEIhOWKTlSLhFVv9EeJioc+a3V4BuTkqW1Bk80OegKyTQcZErVflTXct3L9HzQcdoyFREiS0xyTiIkCV7mTKiWXy8xk2q/Tygt+7gA0HE2252iteFMItMFCAaasVrXBugYf0EHaf9epNcz6TuRbs0boGPeGJV02Z8Z9dCood8KEfypUbsz6hbqwVi3AmjP9Sdm3eO29p2xvhNq35katX1DnogXxrHSFvBJp4v40Q5tlQOyFcO2KbRhpQnG9FYwzNkxw9UZtGeZrAHZ7bwnEBjdpLjccBggALZvxWwgVU5qHCL2Df+7JuLDyYnYCYUWkT2i4n+MxGuNWqAjGHHhqEjsjMX7QlKNU1XSreMqGReJnRJ5X0g8pxXGBZMj6ZFzeTPoqoHpjr+KIK9c3QEdARglKPuaojxPssMyP4r4Gnq1MNzChRMVu5menYiQwxALVk1ibthzqoF3I9YjdzITq89EUxMDPVIgM7HaRAUmJ9YjkzETq81jTke0Ny6xHvmImViN2OTzGLDTCjOxnxDzvcmJ2WkH10Jmx+rNDJ8yLri87Kza3tfvAaN7922IxWsYYqvWeqrbsfbidQADdwNmZyXsa2wGdg0VOx4ZGBeYnbOAM7DbwGDHEwvjArMzGt4M7DYwr2MxY1xgdr7Dn4H9BNjkc5id7ghmYLeBdYWJowIrh+Q5ru/3hE7Q8fTwuHE97Mp2BFQaaxb60f/SneCvIyuMgOsQO2FYl4KD/vwzJgvzywD1yfWaulDeCFWQl6qcs4gIXWZ7LXKkDBUKU9UiOvKLncDJGNbCXh2+qmSqUuQsw8UmUYw4itQ1uyx7rVwoOl50qMdwMfR6wsDrBj7w3zxnYHlH/x+vclW8/mLiUlf72Qn88A8=</diagram></mxfile>
44.9 KB
Loading

problems/1371.find-the-longest-substring-containing-vowels-in-even-counts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ class Solution {
159159
for (int i = len - 1; i >= 0; i--) {
160160

161161
for (int j = 0; j < len - i; j++) {
162-
if (checkValid(preSum, s, i, i + j))
163-
return i + 1
162+
if (checkValid(preSum, s, j, i + j))
163+
return i + 1;
164164
}
165165
}
166-
return 0
166+
return 0;
167167
}
168168

169169

problems/139.word-break.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var wordBreak = function(s, wordDict) {
134134
dp[0] = true;
135135
for (let i = 0; i < s.length + 1; i++) {
136136
for (let word of wordDict) {
137-
if (dp[i - word.length] && word.length <= i) {
137+
if (word.length <= i && dp[i - word.length]) {
138138
if (s.substring(i - word.length, i) === word) {
139139
dp[i] = true;
140140
}

problems/240.search-a-2-d-matrix-ii.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ JavaScript Code:
6969
* @return {boolean}
7070
*/
7171
var searchMatrix = function(matrix, target) {
72-
if (!matrix || matrix.length === 0) return 0;
72+
if (!matrix || matrix.length === 0) return false;
7373

7474
let colIndex = 0;
7575
let rowIndex = matrix.length - 1;

problems/96.unique-binary-search-trees.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ class Solution:
8787
self.visited[n] = res
8888
return res
8989
```
90+
**复杂度分析**
91+
- 时间复杂度:一层循环是 N,另外递归深度是 N,因此总的时间复杂度是 $O(N^2)$
92+
- 空间复杂度:递归的栈深度和visited 的大小都是 N,因此总的空间复杂度为 $O(N)$
9093

9194
## 相关题目
9295

93-
- [95.unique-binary-search-trees-ii](./95.unique-binary-search-trees-ii.md)
96+
- [95.unique-binary-search-trees-ii](https://github.com/azl397985856/leetcode/blob/master/problems/95.unique-binary-search-trees-ii.md)
97+
98+
更多题解可以访问我的LeetCode题解仓库:https://github.com/azl397985856/leetcode 。 目前已经30K star啦。
99+
100+
关注公众号力扣加加,努力用清晰直白的语言还原解题思路,并且有大量图解,手把手教你识别套路,高效刷题。

thinkings/binary-tree-traversal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Solution:
146146
147147
## Morris 遍历
148148

149-
我们可以使用一种叫做 Morris 遍历的方法,既不使用递归也不借助于栈。从而在$O(1)$时间完成这个过程
149+
我们可以使用一种叫做 Morris 遍历的方法,既不使用递归也不借助于栈。从而在 $O(1)$ 空间完成这个过程
150150

151151
```python
152152
def MorrisTraversal(root):

thinkings/trie.en.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Trie
2+
3+
When this article is done (2020-07-13), there are 17 LeetCode problems about [Trie (Prefix Tree)](https://leetcode.com/tag/trie/). Among them, 2 problems are easy, 8 are medium, and 7 are hard.
4+
5+
Here we summarize four of them. Once you figure them out, `Trie` should not be a challenge to you anymore. Hope this article is helpful to you.
6+
7+
The main interface of a trie should include the following:
8+
9+
- `insert(word)`: Insert a word
10+
- `search(word)`: Search for a word
11+
- `startWith(prefix)`: Search for a word with the given prefix
12+
13+
Among all of the above, `startWith` is one of the most essential methods, which leads to the naming for 'Prefix Tree'. You can start with [208.implement-trie-prefix-tree](https://leetcode.com/problems/implement-trie-prefix-tree) to get yourself familiar with this data structure, and then try to solve other problems.
14+
15+
Here's the graph illustration of a trie:
16+
![](../assets/problems/208.implement-trie-prefix-tree-1.en.png)
17+
18+
As the graph shows, each node of the trie would store a character and a boolean `isWord`, which suggests whether the node is the end of a word. There might be some slight differences in the actual implementation, but they are essentially the same.
19+
20+
### Related Problems' Solutions in this Repo (To Be Updated)
21+
- [0208.implement-trie-prefix-tree](https://github.com/azl397985856/leetcode/blob/b8e8fa5f0554926efa9039495b25ed7fc158372a/problems/208.implement-trie-prefix-tree.md)
22+
- [0211.add-and-search-word-data-structure-design](https://github.com/azl397985856/leetcode/blob/b0b69f8f11dace3a9040b54532105d42e88e6599/problems/211.add-and-search-word-data-structure-design.md)
23+
- [0212.word-search-ii](https://github.com/azl397985856/leetcode/blob/b0b69f8f11dace3a9040b54532105d42e88e6599/problems/212.word-search-ii.md)
24+
- [0472.concatenated-words](https://github.com/azl397985856/leetcode/blob/master/problems/472.concatenated-words.md)
25+
- [0820.short-encoding-of-words](https://github.com/azl397985856/leetcode/blob/master/problems/820.short-encoding-of-words.md)

0 commit comments

Comments
 (0)