Skip to content

Commit db7d6e6

Browse files
committed
feat: update lc problems
1 parent 8daacfe commit db7d6e6

File tree

69 files changed

+189
-155
lines changed

Some content is hidden

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

69 files changed

+189
-155
lines changed

solution/0000-0099/0097.Interleaving String/README_EN.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<p>Given strings <code>s1</code>, <code>s2</code>, and <code>s3</code>, find whether <code>s3</code> is formed by an <strong>interleaving</strong> of <code>s1</code> and <code>s2</code>.</p>
88

9-
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where they are divided into <strong>non-empty</strong> substrings such that:</p>
9+
<p>An <strong>interleaving</strong> of two strings <code>s</code> and <code>t</code> is a configuration where <code>s</code> and <code>t</code> are divided into <code>n</code> and <code>m</code> <strong>non-empty</strong> substrings respectively, such that:</p>
1010

1111
<ul>
1212
<li><code>s = s<sub>1</sub> + s<sub>2</sub> + ... + s<sub>n</sub></code></li>
@@ -23,13 +23,18 @@
2323
<pre>
2424
<strong>Input:</strong> s1 = &quot;aabcc&quot;, s2 = &quot;dbbca&quot;, s3 = &quot;aadbbcbcac&quot;
2525
<strong>Output:</strong> true
26+
<strong>Explanation:</strong> One way to obtain s3 is:
27+
Split s1 into s1 = &quot;aa&quot; + &quot;bc&quot; + &quot;c&quot;, and s2 into s2 = &quot;dbbc&quot; + &quot;a&quot;.
28+
Interleaving the two splits, we get &quot;aa&quot; + &quot;dbbc&quot; + &quot;bc&quot; + &quot;a&quot; + &quot;c&quot; = &quot;aadbbcbcac&quot;.
29+
Since s3 can be obtained by interleaving s1 and s2, we return true.
2630
</pre>
2731

2832
<p><strong>Example 2:</strong></p>
2933

3034
<pre>
3135
<strong>Input:</strong> s1 = &quot;aabcc&quot;, s2 = &quot;dbbca&quot;, s3 = &quot;aadbbbaccc&quot;
3236
<strong>Output:</strong> false
37+
<strong>Explanation:</strong> Notice how it is impossible to interleave s2 with any other string to obtain s3.
3338
</pre>
3439

3540
<p><strong>Example 3:</strong></p>

solution/0100-0199/0130.Surrounded Regions/README_EN.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
<pre>
1515
<strong>Input:</strong> board = [[&quot;X&quot;,&quot;X&quot;,&quot;X&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;O&quot;,&quot;O&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;X&quot;,&quot;O&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;O&quot;,&quot;X&quot;,&quot;X&quot;]]
1616
<strong>Output:</strong> [[&quot;X&quot;,&quot;X&quot;,&quot;X&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;X&quot;,&quot;X&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;X&quot;,&quot;X&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;O&quot;,&quot;X&quot;,&quot;X&quot;]]
17-
<strong>Explanation:</strong> Surrounded regions should not be on the border, which means that any &#39;O&#39; on the border of the board are not flipped to &#39;X&#39;. Any &#39;O&#39; that is not on the border and it is not connected to an &#39;O&#39; on the border will be flipped to &#39;X&#39;. Two cells are connected if they are adjacent cells connected horizontally or vertically.
17+
<strong>Explanation:</strong> Notice that an &#39;O&#39; should not be flipped if:
18+
- It is on the border, or
19+
- It is adjacent to an &#39;O&#39; that should not be flipped.
20+
The bottom &#39;O&#39; is on the border, so it is not flipped.
21+
The other three &#39;O&#39; form a surrounded region, so they are flipped.
1822
</pre>
1923

2024
<p><strong>Example 2:</strong></p>

solution/0100-0199/0139.Word Break/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Trie:
9090
def __init__(self):
9191
self.children = [None] * 26
9292
self.is_end = False
93-
93+
9494
def insert(self, w):
9595
node = self
9696
for c in w:
@@ -99,7 +99,7 @@ class Trie:
9999
node.children[idx] = Trie()
100100
node = node.children[idx]
101101
node.is_end = True
102-
102+
103103
def search(self, w):
104104
node = self
105105
for c in w:
@@ -114,7 +114,7 @@ class Solution:
114114
@cache
115115
def dfs(s):
116116
return not s or any(trie.search(s[:i]) and dfs(s[i:]) for i in range(1, len(s) + 1))
117-
117+
118118
trie = Trie()
119119
for w in wordDict:
120120
trie.insert(w)
@@ -269,7 +269,7 @@ public:
269269
270270
bool wordBreak(string s, vector<string>& wordDict) {
271271
for (auto w : wordDict) trie->insert(w);
272-
return dfs(s);
272+
return dfs(s);
273273
}
274274
275275
bool dfs(string s) {

solution/0100-0199/0139.Word Break/README_EN.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Trie:
7272
def __init__(self):
7373
self.children = [None] * 26
7474
self.is_end = False
75-
75+
7676
def insert(self, w):
7777
node = self
7878
for c in w:
@@ -81,7 +81,7 @@ class Trie:
8181
node.children[idx] = Trie()
8282
node = node.children[idx]
8383
node.is_end = True
84-
84+
8585
def search(self, w):
8686
node = self
8787
for c in w:
@@ -96,7 +96,7 @@ class Solution:
9696
@cache
9797
def dfs(s):
9898
return not s or any(trie.search(s[:i]) and dfs(s[i:]) for i in range(1, len(s) + 1))
99-
99+
100100
trie = Trie()
101101
for w in wordDict:
102102
trie.insert(w)
@@ -249,7 +249,7 @@ public:
249249
250250
bool wordBreak(string s, vector<string>& wordDict) {
251251
for (auto w : wordDict) trie->insert(w);
252-
return dfs(s);
252+
return dfs(s);
253253
}
254254
255255
bool dfs(string s) {

solution/0200-0299/0212.Word Search II/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public:
208208
if(node->w != "") res.insert(node->w);
209209
char c = board[i][j];
210210
board[i][j] = '0';
211-
211+
212212
for (int k = 0; k < 4; ++k)
213213
{
214214
int x = i + dirs[k], y = j + dirs[k + 1];

solution/0200-0299/0212.Word Search II/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public:
198198
if(node->w != "") res.insert(node->w);
199199
char c = board[i][j];
200200
board[i][j] = '0';
201-
201+
202202
for (int k = 0; k < 4; ++k)
203203
{
204204
int x = i + dirs[k], y = j + dirs[k + 1];

solution/0200-0299/0215.Kth Largest Element in an Array/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@
1010

1111
<p>请注意,你需要找的是数组排序后的第 <code>k</code> 个最大的元素,而不是第 <code>k</code> 个不同的元素。</p>
1212

13-
<p> </p>
13+
<p>&nbsp;</p>
1414

1515
<p><strong>示例 1:</strong></p>
1616

1717
<pre>
18-
<strong>输入:</strong> <code>[3,2,1,5,6,4]</code> k = 2
18+
<strong>输入:</strong> <code>[3,2,1,5,6,4],</code> k = 2
1919
<strong>输出:</strong> 5
2020
</pre>
2121

22-
<p><strong>示例 2:</strong></p>
22+
<p><strong>示例&nbsp;2:</strong></p>
2323

2424
<pre>
25-
<strong>输入:</strong> <code>[3,2,3,1,2,4,5,5,6]</code> k = 4
25+
<strong>输入:</strong> <code>[3,2,3,1,2,4,5,5,6], </code>k = 4
2626
<strong>输出:</strong> 4</pre>
2727

28-
<p> </p>
28+
<p>&nbsp;</p>
2929

3030
<p><strong>提示: </strong></p>
3131

3232
<ul>
33-
<li><code>1 <= k <= nums.length <= 10<sup>4</sup></code></li>
34-
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
33+
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
34+
<li><code>-10<sup>4</sup>&nbsp;&lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
3535
</ul>
3636

3737
## 解法

solution/0200-0299/0215.Kth Largest Element in an Array/README_EN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
<p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p>
1010

11+
<p>You must solve it in <code>O(n)</code> time complexity.</p>
12+
1113
<p>&nbsp;</p>
1214
<p><strong>Example 1:</strong></p>
1315
<pre><strong>Input:</strong> nums = [3,2,1,5,6,4], k = 2
@@ -20,7 +22,7 @@
2022
<p><strong>Constraints:</strong></p>
2123

2224
<ul>
23-
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
25+
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
2426
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
2527
</ul>
2628

solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README_EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
## Description
66

7-
<p>Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.</p>
7+
<p>Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.</p>
88

9-
<p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <code>q</code> as the lowest node in <code>T</code> that has both <code>p</code> and <code>q</code> as descendants (where we allow <b>a node to be a descendant of itself</b>).&rdquo;</p>
9+
<p>According to the <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" target="_blank">definition of LCA on Wikipedia</a>: &ldquo;The lowest common ancestor is defined between two nodes <code>p</code> and <code>q</code> as the lowest node in <code>T</code> that has both <code>p</code> and <code>q</code> as descendants (where we allow <strong>a node to be a descendant of itself</strong>).&rdquo;</p>
1010

1111
<p>&nbsp;</p>
1212
<p><strong>Example 1:</strong></p>

solution/0200-0299/0243.Shortest Word Distance/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<p><strong>Constraints:</strong></p>
2626

2727
<ul>
28-
<li><code>1 &lt;= wordsDict.length &lt;= 3 * 10<sup>4</sup></code></li>
28+
<li><code>2 &lt;= wordsDict.length &lt;= 3 * 10<sup>4</sup></code></li>
2929
<li><code>1 &lt;= wordsDict[i].length &lt;= 10</code></li>
3030
<li><code>wordsDict[i]</code> consists of lowercase English letters.</li>
3131
<li><code>word1</code> and <code>word2</code> are in <code>wordsDict</code>.</li>

0 commit comments

Comments
 (0)