Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ The data structures mainly include:
- [String Problems](./thinkings/string-problems-en.md)
- [Sliding Window Technique](./thinkings/slide-window.en.md)
- [Union Find](./thinkings/union-find.en.md) 🆕
- [Trie](./thinkings/trie.en.md) 🆕

### Anki Flashcards

Expand Down
1 change: 1 addition & 0 deletions assets/drawio/208.implement-trie-prefix-tree.en.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +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>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ class Solution {
for (int i = len - 1; i >= 0; i--) {

for (int j = 0; j < len - i; j++) {
if (checkValid(preSum, s, i, i + j))
return i + 1
if (checkValid(preSum, s, j, i + j))
return i + 1;
}
}
return 0
return 0;
}


Expand Down
25 changes: 25 additions & 0 deletions thinkings/trie.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Trie

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.

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.

The main interface of a trie should include the following:

- `insert(word)`: Insert a word
- `search(word)`: Search for a word
- `startWith(prefix)`: Search for a word with the given prefix

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.

Here's the graph illustration of a trie:
![](../assets/problems/208.implement-trie-prefix-tree-1.en.png)

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.

### Related Problems' Solutions in this Repo (To Be Updated)
- [0208.implement-trie-prefix-tree](https://github.com/azl397985856/leetcode/blob/b8e8fa5f0554926efa9039495b25ed7fc158372a/problems/208.implement-trie-prefix-tree.md)
- [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)
- [0212.word-search-ii](https://github.com/azl397985856/leetcode/blob/b0b69f8f11dace3a9040b54532105d42e88e6599/problems/212.word-search-ii.md)
- [0472.concatenated-words](https://github.com/azl397985856/leetcode/blob/master/problems/472.concatenated-words.md)
- [0820.short-encoding-of-words](https://github.com/azl397985856/leetcode/blob/master/problems/820.short-encoding-of-words.md)