Skip to content

Commit 21e293a

Browse files
committed
feat: add solutions to lc problems: No.2432~2435
* No.2432.The Employee That Worked on the Longest Task * No.2433.Find The Original Array of Prefix Xor * No.2434.Using a Robot to Print the Lexicographically Smallest String * No.2435.Paths in Matrix Whose Sum Is Divisible by K
1 parent 9d07754 commit 21e293a

File tree

45 files changed

+2132
-63
lines changed

Some content is hidden

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

45 files changed

+2132
-63
lines changed

solution/0000-0099/0045.Jump Game II/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[i]</code>, you can jump to any <code>nums[i + j]</code> where:</p>
1010

1111
<ul>
12-
<li><code>1 &lt;= j &lt;= nums[i]</code> and</li>
12+
<li><code>0 &lt;= j &lt;= nums[i]</code> and</li>
1313
<li><code>i + j &lt; n</code></li>
1414
</ul>
1515

solution/0400-0499/0410.Split Array Largest Sum/README_EN.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,29 @@
44

55
## Description
66

7-
<p>Given an array <code>nums</code> which consists of non-negative integers and an integer <code>m</code>, you can split the array into <code>m</code> non-empty continuous subarrays.</p>
7+
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, split <code>nums</code> into <code>k</code> non-empty subarrays such that the largest sum of any subarray is <strong>minimized</strong>.</p>
88

9-
<p>Write an algorithm to minimize the largest sum among these <code>m</code> subarrays.</p>
9+
<p>Return <em>the minimized largest sum of the split</em>.</p>
10+
11+
<p>A <strong>subarray</strong> is a contiguous part of the array.</p>
1012

1113
<p>&nbsp;</p>
12-
<p><strong>Example 1:</strong></p>
14+
<p><strong class="example">Example 1:</strong></p>
1315

1416
<pre>
15-
<strong>Input:</strong> nums = [7,2,5,10,8], m = 2
17+
<strong>Input:</strong> nums = [7,2,5,10,8], k = 2
1618
<strong>Output:</strong> 18
17-
<strong>Explanation:</strong>
18-
There are four ways to split nums into two subarrays.
19-
The best way is to split it into [7,2,5] and [10,8],
20-
where the largest sum among the two subarrays is only 18.
19+
<strong>Explanation:</strong> There are four ways to split nums into two subarrays.
20+
The best way is to split it into [7,2,5] and [10,8], where the largest sum among the two subarrays is only 18.
2121
</pre>
2222

23-
<p><strong>Example 2:</strong></p>
23+
<p><strong class="example">Example 2:</strong></p>
2424

2525
<pre>
26-
<strong>Input:</strong> nums = [1,2,3,4,5], m = 2
26+
<strong>Input:</strong> nums = [1,2,3,4,5], k = 2
2727
<strong>Output:</strong> 9
28-
</pre>
29-
30-
<p><strong>Example 3:</strong></p>
31-
32-
<pre>
33-
<strong>Input:</strong> nums = [1,4,4], m = 3
34-
<strong>Output:</strong> 4
28+
<strong>Explanation:</strong> There are four ways to split nums into two subarrays.
29+
The best way is to split it into [1,2,3] and [4,5], where the largest sum among the two subarrays is only 9.
3530
</pre>
3631

3732
<p>&nbsp;</p>
@@ -40,7 +35,7 @@ where the largest sum among the two subarrays is only 18.
4035
<ul>
4136
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
4237
<li><code>0 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
43-
<li><code>1 &lt;= m &lt;= min(50, nums.length)</code></li>
38+
<li><code>1 &lt;= k &lt;= min(50, nums.length)</code></li>
4439
</ul>
4540

4641
## Solutions

solution/0500-0599/0505.The Maze II/README_EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ The length of the path is 1 + 1 + 3 + 1 + 2 + 2 + 2 = 12.
4747
<li><code>maze[i][j]</code> is <code>0</code> or <code>1</code>.</li>
4848
<li><code>start.length == 2</code></li>
4949
<li><code>destination.length == 2</code></li>
50-
<li><code>0 &lt;= start<sub>row</sub>, destination<sub>row</sub> &lt;= m</code></li>
51-
<li><code>0 &lt;= start<sub>col</sub>, destination<sub>col</sub> &lt;= n</code></li>
50+
<li><code>0 &lt;= start<sub>row</sub>, destination<sub>row</sub> &lt; m</code></li>
51+
<li><code>0 &lt;= start<sub>col</sub>, destination<sub>col</sub> &lt; n</code></li>
5252
<li>Both the ball and the destination exist in an empty space, and they will not be in the same position initially.</li>
5353
<li>The maze contains <strong>at least 2 empty spaces</strong>.</li>
5454
</ul>

solution/0600-0699/0616.Add Bold Tag in String/README_EN.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,38 @@
44

55
## Description
66

7-
<p>You are given a string <code>s</code> and an array of strings <code>words</code>. You should add a closed pair of bold tag <code>&lt;b&gt;</code> and <code>&lt;/b&gt;</code> to wrap the substrings in <code>s</code> that exist in <code>words</code>. If two such substrings overlap, you should wrap them together with only one pair of closed bold-tag. If two substrings wrapped by bold tags are consecutive, you should combine them.</p>
7+
<p>You are given a string <code>s</code> and an array of strings <code>words</code>.</p>
8+
9+
<p>You should add a closed pair of bold tag <code>&lt;b&gt;</code> and <code>&lt;/b&gt;</code> to wrap the substrings in <code>s</code> that exist in <code>words</code>.</p>
10+
11+
<ul>
12+
<li>If two such substrings overlap, you should wrap them together with only one pair of closed bold-tag.</li>
13+
<li>If two substrings wrapped by bold tags are consecutive, you should combine them.</li>
14+
</ul>
815

916
<p>Return <code>s</code> <em>after adding the bold tags</em>.</p>
1017

1118
<p>&nbsp;</p>
12-
<p><strong>Example 1:</strong></p>
19+
<p><strong class="example">Example 1:</strong></p>
1320

1421
<pre>
1522
<strong>Input:</strong> s = &quot;abcxyz123&quot;, words = [&quot;abc&quot;,&quot;123&quot;]
1623
<strong>Output:</strong> &quot;&lt;b&gt;abc&lt;/b&gt;xyz&lt;b&gt;123&lt;/b&gt;&quot;
24+
<strong>Explanation:</strong> The two strings of words are substrings of s as following: &quot;<u>abc</u>xyz<u>123</u>&quot;.
25+
We add &lt;b&gt; before each substring and &lt;/b&gt; after each substring.
1726
</pre>
1827

19-
<p><strong>Example 2:</strong></p>
28+
<p><strong class="example">Example 2:</strong></p>
2029

2130
<pre>
22-
<strong>Input:</strong> s = &quot;aaabbcc&quot;, words = [&quot;aaa&quot;,&quot;aab&quot;,&quot;bc&quot;]
23-
<strong>Output:</strong> &quot;&lt;b&gt;aaabbc&lt;/b&gt;c&quot;
31+
<strong>Input:</strong> s = &quot;aaabbb&quot;, words = [&quot;aa&quot;,&quot;b&quot;]
32+
<strong>Output:</strong> &quot;&lt;b&gt;aaabbb&lt;/b&gt;&quot;
33+
<strong>Explanation:</strong>
34+
&quot;aa&quot; appears as a substring two times: &quot;<u>aa</u>abbb&quot; and &quot;a<u>aa</u>bbb&quot;.
35+
&quot;b&quot; appears as a substring three times: &quot;aaa<u>b</u>bb&quot;, &quot;aaab<u>b</u>b&quot;, and &quot;aaabb<u>b</u>&quot;.
36+
We add &lt;b&gt; before each substring and &lt;/b&gt; after each substring: &quot;&lt;b&gt;a&lt;b&gt;a&lt;/b&gt;a&lt;/b&gt;&lt;b&gt;b&lt;/b&gt;&lt;b&gt;b&lt;/b&gt;&lt;b&gt;b&lt;/b&gt;&quot;.
37+
Since the first two &lt;b&gt;&#39;s overlap, we merge them: &quot;&lt;b&gt;aaa&lt;/b&gt;&lt;b&gt;b&lt;/b&gt;&lt;b&gt;b&lt;/b&gt;&lt;b&gt;b&lt;/b&gt;&quot;.
38+
Since now the four &lt;b&gt;&#39;s are consecuutive, we merge them: &quot;&lt;b&gt;aaabbb&lt;/b&gt;&quot;.
2439
</pre>
2540

2641
<p>&nbsp;</p>

solution/0700-0799/0744.Find Smallest Letter Greater Than Target/README_EN.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,33 @@
44

55
## Description
66

7-
<p>Given a characters array <code>letters</code> that is sorted in <strong>non-decreasing</strong> order and a character <code>target</code>, return <em>the smallest character in the array that is larger than </em><code>target</code>.</p>
7+
<p>You are given an array of characters <code>letters</code> that is sorted in <strong>non-decreasing order</strong>, and a character <code>target</code>. There are <strong>at least two different</strong> characters in <code>letters</code>.</p>
88

9-
<p><strong>Note</strong> that the letters wrap around.</p>
10-
11-
<ul>
12-
<li>For example, if <code>target == &#39;z&#39;</code> and <code>letters == [&#39;a&#39;, &#39;b&#39;]</code>, the answer is <code>&#39;a&#39;</code>.</li>
13-
</ul>
9+
<p>Return <em>the smallest character in </em><code>letters</code><em> that is lexicographically greater than </em><code>target</code>. If such a character does not exist, return the first character in <code>letters</code>.</p>
1410

1511
<p>&nbsp;</p>
16-
<p><strong>Example 1:</strong></p>
12+
<p><strong class="example">Example 1:</strong></p>
1713

1814
<pre>
1915
<strong>Input:</strong> letters = [&quot;c&quot;,&quot;f&quot;,&quot;j&quot;], target = &quot;a&quot;
2016
<strong>Output:</strong> &quot;c&quot;
17+
<strong>Explanation:</strong> The smallest character that is lexicogrpahically greater than &#39;a&#39; in letters is &#39;c&#39;.
2118
</pre>
2219

23-
<p><strong>Example 2:</strong></p>
20+
<p><strong class="example">Example 2:</strong></p>
2421

2522
<pre>
2623
<strong>Input:</strong> letters = [&quot;c&quot;,&quot;f&quot;,&quot;j&quot;], target = &quot;c&quot;
2724
<strong>Output:</strong> &quot;f&quot;
25+
<strong>Explanation:</strong> The smallest character that is lexicogrpahically greater than &#39;c&#39; in letters is &#39;f&#39;.
2826
</pre>
2927

30-
<p><strong>Example 3:</strong></p>
28+
<p><strong class="example">Example 3:</strong></p>
3129

3230
<pre>
33-
<strong>Input:</strong> letters = [&quot;c&quot;,&quot;f&quot;,&quot;j&quot;], target = &quot;d&quot;
34-
<strong>Output:</strong> &quot;f&quot;
31+
<strong>Input:</strong> letters = [&quot;x&quot;,&quot;x&quot;,&quot;y&quot;,&quot;y&quot;], target = &quot;z&quot;
32+
<strong>Output:</strong> &quot;x&quot;
33+
<strong>Explanation:</strong> There are no characters in letters that is lexicographically greater than &#39;z&#39; so we return letters[0].
3534
</pre>
3635

3736
<p>&nbsp;</p>

solution/0800-0899/0856.Score of Parentheses/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,27 @@
5959

6060
我们用 $d$ 维护当前括号的深度,对于每个 `(`,我们将深度加一,对于每个 `)`,我们将深度减一。当我们遇到 `()` 时,我们将 $2^d$ 加到答案中。
6161

62-
我们举个实际的例子,以 `(()(()))` 为例,我们首先计算内部结构 `()(())` 的分数,然后将分数乘以 2。实际上,我们是在计算 `(()) + ((()))` 的分数。
62+
我们举个实际的例子,以 `(()(()))` 为例,我们首先找到内部两个闭合括号 `()`,然后将分数加上对应的 $2^d$。实际上,我们是在计算 `(()) + ((()))` 的分数。
63+
64+
```bash
65+
( ( ) ( ( ) ) )
66+
^ ^ ^ ^
67+
68+
( ( ) ) + ( ( ( ) ) )
69+
^ ^ ^ ^
70+
```
6371

6472
时间复杂度 $O(n)$,空间复杂度 $O(1)$。其中 $n$ 是字符串的长度。
6573

74+
括号相关类型题:
75+
76+
- [678. 有效的括号字符串](https://github.com/doocs/leetcode/tree/main/solution/0600-0699/0678.Valid%20Parenthesis%20String/README.md)
77+
- [1021. 删除最外层的括号](https://github.com/doocs/leetcode/tree/main/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README.md)
78+
- [1096. 花括号展开 II](https://github.com/doocs/leetcode/tree/main/solution/1000-1099/1096.Brace%20Expansion%20II/README.md)
79+
- [1249. 移除无效的括号](https://github.com/doocs/leetcode/tree/main/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README.md)
80+
- [1541. 平衡括号字符串的最少插入次数](https://github.com/doocs/leetcode/tree/main/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README.md)
81+
- [2116. 判断一个括号字符串是否有效](https://github.com/doocs/leetcode/tree/main/solution/2100-2199/2116.Check%20if%20a%20Parentheses%20String%20Can%20Be%20Valid/README.md)
82+
6683
<!-- tabs:start -->
6784

6885
### **Python3**

solution/0800-0899/0870.Advantage Shuffle/README.md

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

77
<!-- 这里写题目描述 -->
88

9-
<p>给定两个大小相等的数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code>,<code>nums1</code>&nbsp;相对于 <code>nums</code>&nbsp;的<em>优势</em>可以用满足&nbsp;<code>nums1[i] &gt; nums2[i]</code>&nbsp;的索引 <code>i</code>&nbsp;的数目来描述。</p>
9+
<p>给定两个大小相等的数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code>,<code>nums1</code>&nbsp;相对于 <code>nums2</code> 的<em>优势</em>可以用满足&nbsp;<code>nums1[i] &gt; nums2[i]</code>&nbsp;的索引 <code>i</code>&nbsp;的数目来描述。</p>
1010

1111
<p>返回 <font color="#c7254e" face="Menlo, Monaco, Consolas, Courier New, monospace" size="1"><span style="background-color: rgb(249, 242, 244);">nums1</span></font>&nbsp;的<strong>任意</strong>排列,使其相对于 <code>nums2</code>&nbsp;的优势最大化。</p>
1212

solution/0900-0999/0914.X of a Kind in a Deck of Cards/README_EN.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
## Description
66

7-
<p>In a deck of cards, each card has an integer written on it.</p>
7+
<p>You are given an integer array <code>deck</code> where <code>deck[i]</code> represents the number written on the <code>i<sup>th</sup></code> card.</p>
88

9-
<p>Return <code>true</code> if and only if you can choose <code>X &gt;= 2</code> such that it is possible to split the entire deck into 1 or more groups of cards, where:</p>
9+
<p>Partition the cards into <strong>one or more groups</strong> such that:</p>
1010

1111
<ul>
12-
<li>Each group has exactly <code>X</code> cards.</li>
13-
<li>All the cards in each group have the same integer.</li>
12+
<li>Each group has <strong>exactly</strong> <code>x</code> cards where <code>x &gt; 1</code>, and</li>
13+
<li>All the cards in one group have the same integer written on them.</li>
1414
</ul>
1515

16+
<p>Return <code>true</code><em> if such partition is possible, or </em><code>false</code><em> otherwise</em>.</p>
17+
1618
<p>&nbsp;</p>
1719
<p><strong>Example 1:</strong></p>
1820

solution/1100-1199/1155.Number of Dice Rolls With Target Sum/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>You have <code>n</code> dice and each die has <code>k</code> faces numbered from <code>1</code> to <code>k</code>.</p>
7+
<p>You have <code>n</code> dice, and each die has <code>k</code> faces numbered from <code>1</code> to <code>k</code>.</p>
88

9-
<p>Given three integers <code>n</code>, <code>k</code>, and <code>target</code>, return <em>the number of possible ways (out of the </em><code>k<sup>n</sup></code><em> total ways) </em><em>to roll the dice so the sum of the face-up numbers equals </em><code>target</code>. Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
9+
<p>Given three integers <code>n</code>, <code>k</code>, and <code>target</code>, return <em>the number of possible ways (out of the </em><code>k<sup>n</sup></code><em> total ways) </em><em>to roll the dice, so the sum of the face-up numbers equals </em><code>target</code>. Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
1010

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

solution/1200-1299/1262.Greatest Sum Divisible by Three/README_EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
<p><strong>Constraints:</strong></p>
3535

3636
<ul>
37-
<li><code>1 &lt;= nums.length &lt;= 4 * 10^4</code></li>
38-
<li><code>1 &lt;= nums[i] &lt;= 10^4</code></li>
37+
<li><code>1 &lt;= nums.length &lt;= 4 * 10<sup>4</sup></code></li>
38+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
3939
</ul>
4040

4141
## Solutions

0 commit comments

Comments
 (0)