Skip to content

Commit eef5a2f

Browse files
updating all READMEs
1 parent eb3f67f commit eef5a2f

File tree

13 files changed

+1058
-156
lines changed

13 files changed

+1058
-156
lines changed

.dev/logs.json

+32-16
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,10 @@
503503
"sols": {}
504504
},
505505
"106": {
506-
"len": 0,
507-
"sols": {}
506+
"len": 2,
507+
"sols": {
508+
"construct_binary_tree_from_inorder_and_postorder_traversal.go": "3bf889e4e948059e4ae2712fd444d2c6a24fffd0bc51fb224577700de84a23f3"
509+
}
508510
},
509511
"107": {
510512
"len": 0,
@@ -982,8 +984,10 @@
982984
"sols": {}
983985
},
984986
"211": {
985-
"len": 0,
986-
"sols": {}
987+
"len": 2,
988+
"sols": {
989+
"design_add_and_search_words_data_structure.go": "f035897eeefd8eff6ecae6c7ee62b41ad404b70eef8d62ce0993eee71786bee6"
990+
}
987991
},
988992
"212": {
989993
"len": 0,
@@ -2092,8 +2096,10 @@
20922096
"sols": {}
20932097
},
20942098
"463": {
2095-
"len": 0,
2096-
"sols": {}
2099+
"len": 2,
2100+
"sols": {
2101+
"island_perimeter.rs": "bf9e9fd8f1a916a9a7f690a827d62130708c5061f728a99d8ebb21767291e1fa"
2102+
}
20972103
},
20982104
"464": {
20992105
"len": 0,
@@ -2691,8 +2697,10 @@
26912697
"sols": {}
26922698
},
26932699
"605": {
2694-
"len": 0,
2695-
"sols": {}
2700+
"len": 2,
2701+
"sols": {
2702+
"can_place_flowers.py": "d0b8c774567bf5260cc437de5abaa247f003fa63c9652023e9239015de86b55f"
2703+
}
26962704
},
26972705
"606": {
26982706
"len": 0,
@@ -4129,8 +4137,10 @@
41294137
"sols": {}
41304138
},
41314139
"958": {
4132-
"len": 0,
4133-
"sols": {}
4140+
"len": 2,
4141+
"sols": {
4142+
"check_completeness_of_a_binary_tree.go": "0198f20ad717aa6b08b91496a254ec1862b2329bd915b0095af03d7f508a0165"
4143+
}
41344144
},
41354145
"959": {
41364146
"len": 0,
@@ -6037,8 +6047,10 @@
60376047
"sols": {}
60386048
},
60396049
"1431": {
6040-
"len": 0,
6041-
"sols": {}
6050+
"len": 4,
6051+
"sols": {
6052+
"kids_with_the_greatest_number_of_candies.go": "806440bf922c44de9e5d554fc2fdd0db4c70106596b548345ecc2650a6cd7bea"
6053+
}
60426054
},
60436055
"1432": {
60446056
"len": 0,
@@ -6205,8 +6217,10 @@
62056217
"sols": {}
62066218
},
62076219
"1472": {
6208-
"len": 0,
6209-
"sols": {}
6220+
"len": 2,
6221+
"sols": {
6222+
"design_browser_history.go": "8b5ff8b5a2a9367705a19d7c7e698a1b039bd5de98333215ed5d6888db4c956f"
6223+
}
62106224
},
62116225
"1473": {
62126226
"len": 0,
@@ -9747,8 +9761,10 @@
97479761
"sols": {}
97489762
},
97499763
"2348": {
9750-
"len": 0,
9751-
"sols": {}
9764+
"len": 2,
9765+
"sols": {
9766+
"number_of_zero_filled_subarrays.rs": "20289bcb4292fb532364f1d1885b5f5f7ad5d0bc466998d35f861dbc69da6f8b"
9767+
}
97529768
},
97539769
"2349": {
97549770
"len": 0,

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
[**_Rejection Sampling_**][rejection sampling]   
9696
[**_Biconnected Component_**][biconnected component]
9797

98-
### **Total Problems Solved: _177_**
98+
### **Total Problems Solved: _185_**
9999

100100
---
101101

TOPICWISE.md

+168-138
Large diffs are not rendered by default.

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ It might take some time to reflect changes from the repository.
103103
[**_Rejection Sampling_**][rejection sampling]   
104104
[**_Biconnected Component_**][biconnected component]
105105

106-
### **Total Problems Solved: _177_**
106+
### **Total Problems Solved: _185_**
107107

108108
## Contributors
109109

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# 106. Construct Binary Tree from Inorder and Postorder Traversal [![share]](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/)
2+
3+
![][medium]
4+
5+
## Problem Statement
6+
7+
<p>Given two integer arrays <code>inorder</code> and <code>postorder</code> where <code>inorder</code> is the inorder traversal of a binary tree and <code>postorder</code> is the postorder traversal of the same tree, construct and return <em>the binary tree</em>.</p>
8+
<p> </p>
9+
<p><strong class="example">Example 1:</strong></p>
10+
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree.jpg" style="width: 277px; height: 302px;"/>
11+
12+
```
13+
Input: inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]
14+
Output: [3,9,20,null,null,15,7]
15+
```
16+
17+
<p><strong class="example">Example 2:</strong></p>
18+
19+
```
20+
Input: inorder = [-1], postorder = [-1]
21+
Output: [-1]
22+
```
23+
24+
<p> </p>
25+
<p><strong>Constraints:</strong></p>
26+
<ul>
27+
<li><code>1 &lt;= inorder.length &lt;= 3000</code></li>
28+
<li><code>postorder.length == inorder.length</code></li>
29+
<li><code>-3000 &lt;= inorder[i], postorder[i] &lt;= 3000</code></li>
30+
<li><code>inorder</code> and <code>postorder</code> consist of <strong>unique</strong> values.</li>
31+
<li>Each value of <code>postorder</code> also appears in <code>inorder</code>.</li>
32+
<li><code>inorder</code> is <strong>guaranteed</strong> to be the inorder traversal of the tree.</li>
33+
<li><code>postorder</code> is <strong>guaranteed</strong> to be the postorder traversal of the tree.</li>
34+
</ul>
35+
36+
## Solutions
37+
38+
### [_Go_](construct_binary_tree_from_inorder_and_postorder_traversal.go)
39+
40+
```go [Go]
41+
package main
42+
43+
// Definition for a binary tree node.
44+
type TreeNode struct {
45+
Val int
46+
Left *TreeNode
47+
Right *TreeNode
48+
}
49+
50+
func buildTree(inorder []int, postorder []int) *TreeNode {
51+
mapInOrder := make(map[int]int)
52+
53+
for i, v := range inorder {
54+
mapInOrder[v] = i
55+
}
56+
57+
var helper func(int, int) *TreeNode
58+
helper = func(left, right int) *TreeNode {
59+
if left > right {
60+
return nil
61+
}
62+
63+
pop := postorder[len(postorder)-1]
64+
postorder = postorder[:len(postorder)-1]
65+
66+
root := &TreeNode{Val: pop}
67+
mid := mapInOrder[pop]
68+
root.Right = helper(mid+1, right)
69+
root.Left = helper(left, mid-1)
70+
71+
return root
72+
}
73+
74+
return helper(0, len(inorder)-1)
75+
}
76+
77+
```
78+
79+
### [_..._]()
80+
81+
```
82+
83+
```
84+
85+
<!----------------------------------{ link }--------------------------------->
86+
87+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
88+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
89+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
90+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# 211. Design Add and Search Words Data Structure [![share]](https://leetcode.com/problems/design-add-and-search-words-data-structure/)
2+
3+
![][medium]
4+
5+
## Problem Statement
6+
7+
<p>Design a data structure that supports adding new words and finding if a string matches any previously added string.</p>
8+
<p>Implement the <code>WordDictionary</code> class:</p>
9+
<ul>
10+
<li><code>WordDictionary()</code> Initializes the object.</li>
11+
<li><code>void addWord(word)</code> Adds <code>word</code> to the data structure, it can be matched later.</li>
12+
<li><code>bool search(word)</code> Returns <code>true</code> if there is any string in the data structure that matches <code>word</code> or <code>false</code> otherwise. <code>word</code> may contain dots <code>'.'</code> where dots can be matched with any letter.</li>
13+
</ul>
14+
<p> </p>
15+
<p><strong class="example">Example:</strong></p>
16+
17+
```
18+
Input
19+
["WordDictionary","addWord","addWord","addWord","search","search","search","search"]
20+
[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
21+
Output
22+
[null,null,null,null,false,true,true,true]
23+
24+
Explanation
25+
WordDictionary wordDictionary = new WordDictionary();
26+
wordDictionary.addWord("bad");
27+
wordDictionary.addWord("dad");
28+
wordDictionary.addWord("mad");
29+
wordDictionary.search("pad"); // return False
30+
wordDictionary.search("bad"); // return True
31+
wordDictionary.search(".ad"); // return True
32+
wordDictionary.search("b.."); // return True
33+
```
34+
35+
<p> </p>
36+
<p><strong>Constraints:</strong></p>
37+
<ul>
38+
<li><code>1 &lt;= word.length &lt;= 25</code></li>
39+
<li><code>word</code> in <code>addWord</code> consists of lowercase English letters.</li>
40+
<li><code>word</code> in <code>search</code> consist of <code>'.'</code> or lowercase English letters.</li>
41+
<li>There will be at most <code>2</code> dots in <code>word</code> for <code>search</code> queries.</li>
42+
<li>At most <code>10<sup>4</sup></code> calls will be made to <code>addWord</code> and <code>search</code>.</li>
43+
</ul>
44+
45+
<details>
46+
<summary>
47+
48+
#### _Click to open Hints_
49+
50+
</summary>
51+
52+
- You should be familiar with how a Trie works. If not, please work on this problem: <a href="https://leetcode.com/problems/implement-trie-prefix-tree/">Implement Trie (Prefix Tree)</a> first.
53+
54+
</details>
55+
56+
## Solutions
57+
58+
### [_Go_](design_add_and_search_words_data_structure.go)
59+
60+
```go [Go]
61+
package main
62+
63+
type WordDictionary struct {
64+
children [26]* WordDictionary
65+
isWord bool
66+
67+
}
68+
69+
70+
func Constructor() WordDictionary {
71+
return WordDictionary{}
72+
}
73+
74+
75+
func (this *WordDictionary) AddWord(word string) {
76+
root := this
77+
78+
for _,item := range word{
79+
char := item - 'a'
80+
81+
if root.children[char] == nil {
82+
root.children[char] = &WordDictionary{}
83+
}
84+
root = root.children[char]
85+
}
86+
root.isWord = true
87+
88+
}
89+
90+
91+
func (this *WordDictionary) Search(word string) bool {
92+
root := this
93+
for i,item := range word{
94+
if word[i] == '.'{
95+
for _,item := range root.children{
96+
if item != nil && item.Search(word[i+1:]) {
97+
return true
98+
}
99+
}
100+
101+
return false
102+
}
103+
104+
char := item - 'a'
105+
if root.children[char] == nil{
106+
return false
107+
}
108+
root = root.children[char]
109+
}
110+
111+
return root.isWord
112+
}
113+
114+
```
115+
116+
### [_..._]()
117+
118+
```
119+
120+
```
121+
122+
<!----------------------------------{ link }--------------------------------->
123+
124+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
125+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
126+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
127+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg

0 commit comments

Comments
 (0)