Skip to content

Commit fac4075

Browse files
committed
feat: add new lc problems
1 parent cc645a0 commit fac4075

File tree

29 files changed

+772
-36
lines changed

29 files changed

+772
-36
lines changed

solution/0300-0399/0336.Palindrome Pairs/README_EN.md

+17-6
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,41 @@
44

55
## Description
66

7-
<p>Given a list of <b>unique</b> words, return all the pairs of the&nbsp;<b><i>distinct</i></b> indices <code>(i, j)</code> in the given list, so that the concatenation of the two words&nbsp;<code>words[i] + words[j]</code> is a palindrome.</p>
7+
<p>You are given a <strong>0-indexed</strong> array of <strong>unique</strong> strings <code>words</code>.</p>
8+
9+
<p>A <strong>palindrome pair</strong> is a pair of integers <code>(i, j)</code> such that:</p>
10+
11+
<ul>
12+
<li><code>0 &lt;= i, j &lt; word.length</code>,</li>
13+
<li><code>i != j</code>, and</li>
14+
<li><code>words[i] + words[j]</code> (the concatenation of the two strings) is a palindrome string.</li>
15+
</ul>
16+
17+
<p>Return <em>an array of all the <strong>palindrome pairs</strong> of </em><code>words</code>.</p>
818

919
<p>&nbsp;</p>
10-
<p><strong>Example 1:</strong></p>
20+
<p><strong class="example">Example 1:</strong></p>
1121

1222
<pre>
1323
<strong>Input:</strong> words = [&quot;abcd&quot;,&quot;dcba&quot;,&quot;lls&quot;,&quot;s&quot;,&quot;sssll&quot;]
1424
<strong>Output:</strong> [[0,1],[1,0],[3,2],[2,4]]
15-
<strong>Explanation:</strong> The palindromes are [&quot;dcbaabcd&quot;,&quot;abcddcba&quot;,&quot;slls&quot;,&quot;llssssll&quot;]
25+
<strong>Explanation:</strong> The palindromes are [&quot;abcddcba&quot;,&quot;dcbaabcd&quot;,&quot;slls&quot;,&quot;llssssll&quot;]
1626
</pre>
1727

18-
<p><strong>Example 2:</strong></p>
28+
<p><strong class="example">Example 2:</strong></p>
1929

2030
<pre>
2131
<strong>Input:</strong> words = [&quot;bat&quot;,&quot;tab&quot;,&quot;cat&quot;]
2232
<strong>Output:</strong> [[0,1],[1,0]]
2333
<strong>Explanation:</strong> The palindromes are [&quot;battab&quot;,&quot;tabbat&quot;]
2434
</pre>
2535

26-
<p><strong>Example 3:</strong></p>
36+
<p><strong class="example">Example 3:</strong></p>
2737

2838
<pre>
2939
<strong>Input:</strong> words = [&quot;a&quot;,&quot;&quot;]
3040
<strong>Output:</strong> [[0,1],[1,0]]
41+
<strong>Explanation:</strong> The palindromes are [&quot;a&quot;,&quot;a&quot;]
3142
</pre>
3243

3344
<p>&nbsp;</p>
@@ -36,7 +47,7 @@
3647
<ul>
3748
<li><code>1 &lt;= words.length &lt;= 5000</code></li>
3849
<li><code>0 &lt;= words[i].length &lt;= 300</code></li>
39-
<li><code>words[i]</code> consists of lower-case English letters.</li>
50+
<li><code>words[i]</code> consists of lowercase English letters.</li>
4051
</ul>
4152

4253
## Solutions

solution/0300-0399/0348.Design Tic-Tac-Toe/README_EN.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
<li>A player who succeeds in placing <code>n</code> of their marks in a horizontal, vertical, or diagonal row wins the game.</li>
1313
</ol>
1414

15-
<p>Implement the&nbsp;<code>TicTacToe</code> class:</p>
15+
<p>Implement the <code>TicTacToe</code> class:</p>
1616

1717
<ul>
1818
<li><code>TicTacToe(int n)</code> Initializes the object the size of the board <code>n</code>.</li>
19-
<li><code>int move(int row, int col, int player)</code> Indicates that the player with id <code>player</code> plays at the cell <code>(row, col)</code> of the board. The move is guaranteed to be a valid move.</li>
19+
<li><code>int move(int row, int col, int player)</code> Indicates that the player with id <code>player</code> plays at the cell <code>(row, col)</code> of the board. The move is guaranteed to be a valid move, and the two players alternate in making moves. Return
20+
<ul>
21+
<li><code>0</code> if there is <strong>no winner</strong> after the move,</li>
22+
<li><code>1</code> if <strong>player 1</strong> is the winner after the move, or</li>
23+
<li><code>2</code> if <strong>player 2</strong> is the winner after the move.</li>
24+
</ul>
25+
</li>
2026
</ul>
2127

2228
<p>&nbsp;</p>

solution/0400-0499/0493.Reverse Pairs/README_EN.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
<p>Given an integer array <code>nums</code>, return <em>the number of <strong>reverse pairs</strong> in the array</em>.</p>
88

9-
<p>A reverse pair is a pair <code>(i, j)</code> where <code>0 &lt;= i &lt; j &lt; nums.length</code> and <code>nums[i] &gt; 2 * nums[j]</code>.</p>
9+
<p>A <strong>reverse pair</strong> is a pair <code>(i, j)</code> where:</p>
10+
11+
<ul>
12+
<li><code>0 &lt;= i &lt; j &lt; nums.length</code> and</li>
13+
<li><code>nums[i] &gt; 2 * nums[j]</code>.</li>
14+
</ul>
1015

1116
<p>&nbsp;</p>
1217
<p><strong>Example 1:</strong></p>
@@ -27,7 +32,7 @@
2732
<strong>Explanation:</strong> The reverse pairs are:
2833
(1, 4) --&gt; nums[1] = 4, nums[4] = 1, 4 &gt; 2 * 1
2934
(2, 4) --&gt; nums[2] = 3, nums[4] = 1, 3 &gt; 2 * 1
30-
(3, 4) --&gt; nums[3] = 3, nums[4] = 1, 5 &gt; 2 * 1
35+
(3, 4) --&gt; nums[3] = 5, nums[4] = 1, 5 &gt; 2 * 1
3136
</pre>
3237

3338
<p>&nbsp;</p>

solution/0700-0799/0718.Maximum Length of Repeated Subarray/README_EN.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
<p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>the maximum length of a subarray that appears in <strong>both</strong> arrays</em>.</p>
88

99
<p>&nbsp;</p>
10-
<p><strong>Example 1:</strong></p>
10+
<p><strong class="example">Example 1:</strong></p>
1111

1212
<pre>
1313
<strong>Input:</strong> nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]
1414
<strong>Output:</strong> 3
1515
<strong>Explanation:</strong> The repeated subarray with maximum length is [3,2,1].
1616
</pre>
1717

18-
<p><strong>Example 2:</strong></p>
18+
<p><strong class="example">Example 2:</strong></p>
1919

2020
<pre>
2121
<strong>Input:</strong> nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]
2222
<strong>Output:</strong> 5
23+
<strong>Explanation:</strong> The repeated subarray with maximum length is [0,0,0,0,0].
2324
</pre>
2425

2526
<p>&nbsp;</p>

solution/0700-0799/0775.Global and Local Inversions/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
<strong>解释:</strong>有 2 个全局倒置,和 1 个局部倒置。
4343
</pre>
4444

45+
46+
4547
<p><strong>提示:</strong></p>
4648

4749
<ul>

solution/0800-0899/0854.K-Similar Strings/README_EN.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@
99
<p>Given two anagrams <code>s1</code> and <code>s2</code>, return the smallest <code>k</code> for which <code>s1</code> and <code>s2</code> are <code>k</code><strong>-similar</strong>.</p>
1010

1111
<p>&nbsp;</p>
12-
<p><strong>Example 1:</strong></p>
12+
<p><strong class="example">Example 1:</strong></p>
1313

1414
<pre>
1515
<strong>Input:</strong> s1 = &quot;ab&quot;, s2 = &quot;ba&quot;
1616
<strong>Output:</strong> 1
17+
<strong>Explanation:</strong> The two string are 1-similar because we can use one swap to change s1 to s2: &quot;ab&quot; --&gt; &quot;ba&quot;.
1718
</pre>
1819

19-
<p><strong>Example 2:</strong></p>
20+
<p><strong class="example">Example 2:</strong></p>
2021

2122
<pre>
2223
<strong>Input:</strong> s1 = &quot;abc&quot;, s2 = &quot;bca&quot;
2324
<strong>Output:</strong> 2
25+
<strong>Explanation:</strong> The two strings are 2-similar because we can use two swaps to change s1 to s2: &quot;abc&quot; --&gt; &quot;bac&quot; --&gt; &quot;bca&quot;.
2426
</pre>
2527

2628
<p>&nbsp;</p>

solution/1000-1099/1012.Numbers With Repeated Digits/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class Solution:
109109
class Solution:
110110
def numDupDigitsAtMostN(self, n: int) -> int:
111111
return n - self.f(n)
112-
112+
113113
def f(self, n):
114114
@cache
115115
def dfs(pos, mask, lead, limit):

solution/1000-1099/1012.Numbers With Repeated Digits/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Solution:
7777
class Solution:
7878
def numDupDigitsAtMostN(self, n: int) -> int:
7979
return n - self.f(n)
80-
80+
8181
def f(self, n):
8282
@cache
8383
def dfs(pos, mask, lead, limit):

solution/1700-1799/1770.Maximum Score from Performing Multiplication Operations/README_EN.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44

55
## Description
66

7-
<p>You are given two integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>. The arrays are <strong>1-indexed</strong>.</p>
7+
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p>
88

9-
<p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</code> operations. On the <code>i<sup>th</sup></code> operation <strong>(1-indexed)</strong>, you will:</p>
9+
<p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</code> operations. On the <code>i<sup>th</sup></code> operation (<strong>0-indexed</strong>) you will:</p>
1010

1111
<ul>
12-
<li>Choose one integer <code>x</code> from <strong>either the start or the end </strong>of the array <code>nums</code>.</li>
13-
<li>Add <code>multipliers[i] * x</code> to your score.</li>
14-
<li>Remove <code>x</code> from the array <code>nums</code>.</li>
12+
<li>Choose one integer <code>x</code> from <strong>either the start or the end </strong>of the array <code>nums</code>.</li>
13+
<li>Add <code>multipliers[i] * x</code> to your score.
14+
<ul>
15+
<li>Note that <code>multipliers[0]</code> corresponds to the first operation, <code>multipliers[1]</code> to the second operation, and so on.</li>
16+
</ul>
17+
</li>
18+
<li>Remove <code>x</code> from <code>nums</code>.</li>
1519
</ul>
1620

1721
<p>Return <em>the <strong>maximum</strong> score after performing </em><code>m</code> <em>operations.</em></p>
@@ -48,7 +52,7 @@ The total score is 50 + 15 - 9 + 4 + 42 = 102.
4852
<ul>
4953
<li><code>n == nums.length</code></li>
5054
<li><code>m == multipliers.length</code></li>
51-
<li><code>1 &lt;= m &lt;= 10<sup>3</sup></code></li>
55+
<li><code>1 &lt;= m &lt;= 300</code></li>
5256
<li><code>m &lt;= n &lt;= 10<sup>5</sup></code><code> </code></li>
5357
<li><code>-1000 &lt;= nums[i], multipliers[i] &lt;= 1000</code></li>
5458
</ul>

solution/2300-2399/2376.Count Special Integers/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Solution {
178178
class Solution {
179179
private int[] a = new int[11];
180180
private int[][] dp = new int[11][1 << 11];
181-
181+
182182
public int countSpecialNumbers(int n) {
183183
return f(n);
184184
}

solution/2300-2399/2376.Count Special Integers/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class Solution {
148148
class Solution {
149149
private int[] a = new int[11];
150150
private int[][] dp = new int[11][1 << 11];
151-
151+
152152
public int countSpecialNumbers(int n) {
153153
return f(n);
154154
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [2418. 按身高排序](https://leetcode.cn/problems/sort-the-people)
2+
3+
[English Version](/solution/2400-2499/2418.Sort%20the%20People/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个字符串数组 <code>names</code> ,和一个由 <strong>互不相同</strong> 的正整数组成的数组 <code>heights</code> 。两个数组的长度均为 <code>n</code> 。</p>
10+
11+
<p>对于每个下标 <code>i</code>,<code>names[i]</code> 和 <code>heights[i]</code> 表示第 <code>i</code> 个人的名字和身高。</p>
12+
13+
<p>请按身高 <strong>降序</strong> 顺序返回对应的名字数组 <code>names</code> 。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
19+
<pre><strong>输入:</strong>names = ["Mary","John","Emma"], heights = [180,165,170]
20+
<strong>输出:</strong>["Mary","Emma","John"]
21+
<strong>解释:</strong>Mary 最高,接着是 Emma 和 John 。
22+
</pre>
23+
24+
<p><strong>示例 2:</strong></p>
25+
26+
<pre><strong>输入:</strong>names = ["Alice","Bob","Bob"], heights = [155,185,150]
27+
<strong>输出:</strong>["Bob","Alice","Bob"]
28+
<strong>解释:</strong>第一个 Bob 最高,然后是 Alice 和第二个 Bob 。
29+
</pre>
30+
31+
<p>&nbsp;</p>
32+
33+
<p><strong>提示:</strong></p>
34+
35+
<ul>
36+
<li><code>n == names.length == heights.length</code></li>
37+
<li><code>1 &lt;= n &lt;= 10<sup>3</sup></code></li>
38+
<li><code>1 &lt;= names[i].length &lt;= 20</code></li>
39+
<li><code>1 &lt;= heights[i] &lt;= 10<sup>5</sup></code></li>
40+
<li><code>names[i]</code> 由大小写英文字母组成</li>
41+
<li><code>heights</code> 中的所有值互不相同</li>
42+
</ul>
43+
44+
## 解法
45+
46+
<!-- 这里可写通用的实现逻辑 -->
47+
48+
<!-- tabs:start -->
49+
50+
### **Python3**
51+
52+
<!-- 这里可写当前语言的特殊实现逻辑 -->
53+
54+
```python
55+
56+
```
57+
58+
### **Java**
59+
60+
<!-- 这里可写当前语言的特殊实现逻辑 -->
61+
62+
```java
63+
64+
```
65+
66+
### **TypeScript**
67+
68+
```ts
69+
70+
```
71+
72+
### **...**
73+
74+
```
75+
76+
```
77+
78+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# [2418. Sort the People](https://leetcode.com/problems/sort-the-people)
2+
3+
[中文文档](/solution/2400-2499/2418.Sort%20the%20People/README.md)
4+
5+
## Description
6+
7+
<p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
8+
9+
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <code>i<sup>th</sup></code> person.</p>
10+
11+
<p>Return <code>names</code><em> sorted in <strong>descending</strong> order by the people&#39;s heights</em>.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> names = [&quot;Mary&quot;,&quot;John&quot;,&quot;Emma&quot;], heights = [180,165,170]
18+
<strong>Output:</strong> [&quot;Mary&quot;,&quot;Emma&quot;,&quot;John&quot;]
19+
<strong>Explanation:</strong> Mary is the tallest, followed by Emma and John.
20+
</pre>
21+
22+
<p><strong>Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> names = [&quot;Alice&quot;,&quot;Bob&quot;,&quot;Bob&quot;], heights = [155,185,150]
26+
<strong>Output:</strong> [&quot;Bob&quot;,&quot;Alice&quot;,&quot;Bob&quot;]
27+
<strong>Explanation:</strong> The first Bob is the tallest, followed by Alice and the second Bob.
28+
</pre>
29+
30+
<p>&nbsp;</p>
31+
<p><strong>Constraints:</strong></p>
32+
33+
<ul>
34+
<li><code>n == names.length == heights.length</code></li>
35+
<li><code>1 &lt;= n &lt;= 10<sup>3</sup></code></li>
36+
<li><code>1 &lt;= names[i].length &lt;= 20</code></li>
37+
<li><code>1 &lt;= heights[i] &lt;= 10<sup>5</sup></code></li>
38+
<li><code>names[i]</code> consists of lower and upper case English letters.</li>
39+
<li>All the values of <code>heights</code> are distinct.</li>
40+
</ul>
41+
42+
## Solutions
43+
44+
<!-- tabs:start -->
45+
46+
### **Python3**
47+
48+
```python
49+
50+
```
51+
52+
### **Java**
53+
54+
```java
55+
56+
```
57+
58+
### **TypeScript**
59+
60+
```ts
61+
62+
```
63+
64+
### **...**
65+
66+
```
67+
68+
```
69+
70+
<!-- tabs:end -->

0 commit comments

Comments
 (0)