Skip to content

feat: update lc problems #3961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2025
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
2 changes: 1 addition & 1 deletion solution/0400-0499/0480.Sliding Window Median/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tags:
<pre>
<strong>Input:</strong> nums = [1,3,-1,-3,5,3,6,7], k = 3
<strong>Output:</strong> [1.00000,-1.00000,-1.00000,3.00000,5.00000,6.00000]
<strong>Explanation:</strong>
<strong>Explanation:</strong>
Window position Median
--------------- -----
[<strong>1 3 -1</strong>] -3 5 3 6 7 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fileSystem.readContentFromFile("/a/b/c/d"); // 返回 "hello"</pre>
<li><code>path</code>&nbsp;和&nbsp;<code>filePath</code>&nbsp;都是绝对路径,除非是根目录&nbsp;<code>‘/’</code>&nbsp;自身,其他路径都是以&nbsp;<code>‘/’</code>&nbsp;开头且 <strong>不</strong> 以&nbsp;<code>‘/’</code>&nbsp;结束。</li>
<li>你可以假定所有操作的参数都是有效的,即用户不会获取不存在文件的内容,或者获取不存在文件夹和文件的列表。</li>
<li>你可以假定所有文件夹名字和文件名字都只包含小写字母,且同一文件夹下不会有相同名字的文件夹或文件。</li>
<li>你可以假定&nbsp;<code>addContentToFile</code> 中的文件的父目录都存在。</li>
<li><code>1 &lt;= content.length &lt;= 50</code></li>
<li><code>ls</code>,&nbsp;<code>mkdir</code>,&nbsp;<code>addContentToFile</code>, and&nbsp;<code>readContentFromFile</code>&nbsp;最多被调用&nbsp;<code>300</code>&nbsp;次</li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions solution/0700-0799/0731.My Calendar II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ tags:

<strong>Explanation</strong>
MyCalendarTwo myCalendarTwo = new MyCalendarTwo();
myCalendarTwo.book(10, 20); // return True, The event can be booked.
myCalendarTwo.book(50, 60); // return True, The event can be booked.
myCalendarTwo.book(10, 40); // return True, The event can be double booked.
myCalendarTwo.book(10, 20); // return True, The event can be booked.
myCalendarTwo.book(50, 60); // return True, The event can be booked.
myCalendarTwo.book(10, 40); // return True, The event can be double booked.
myCalendarTwo.book(5, 15); // return False, The event cannot be booked, because it would result in a triple booking.
myCalendarTwo.book(5, 10); // return True, The event can be booked, as it does not use time 10 which is already double booked.
myCalendarTwo.book(25, 55); // return True, The event can be booked, as the time in [25, 40) will be double booked with the third event, the time [40, 50) will be single booked, and the time [50, 55) will be double booked with the second event.
Expand Down
43 changes: 16 additions & 27 deletions solution/0900-0999/0916.Word Subsets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,36 @@ tags:

<p>如果对 <code>words2</code> 中的每一个单词&nbsp;<code>b</code>,<code>b</code> 都是 <code>a</code> 的子集,那么我们称&nbsp;<code>words1</code> 中的单词 <code>a</code> 是<em> </em><strong>通用单词</strong><em> </em>。</p>

<p>以数组形式返回&nbsp;<code>words1</code> 中所有的通用单词。你可以按 <strong>任意顺序</strong> 返回答案。</p>
<p>以数组形式返回&nbsp;<code>words1</code> 中所有的 <strong>通用</strong> 单词。你可以按 <strong>任意顺序</strong> 返回答案。</p>

<p>&nbsp;</p>

<ol>
</ol>

<p><strong>示例 1:</strong></p>
<p><strong class="example">示例 1:</strong></p>

<pre>
<strong>输入:</strong>words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","o"]
<strong>输出:</strong>["facebook","google","leetcode"]
</pre>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","o"]</span></p>

<p><strong>示例 2:</strong></p>
<p><span class="example-io"><b>输出:</b>["facebook","google","leetcode"]</span></p>
</div>

<pre>
<strong>输入:</strong>words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["l","e"]
<strong>输出:</strong>["apple","google","leetcode"]
</pre>
<p><strong class="example">示例 2:</strong></p>

<p><strong>示例 3:</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b></span><span class="example-io">words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["lc","eo"]</span></p>

<pre>
<strong>输入:</strong>words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","oo"]
<strong>输出:</strong>["facebook","google"]
</pre>
<p><span class="example-io"><b>输出:</b></span><span class="example-io">["leetcode"]</span></p>
</div>

<p><strong>示例 4:</strong></p>
<p><strong class="example">示例 3:</strong></p>

<pre>
<strong>输入:</strong>words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["lo","eo"]
<strong>输出:</strong>["google","leetcode"]
</pre>
<div class="example-block">
<p><span class="example-io"><b>输入:</b></span><span class="example-io">words1 = ["acaac","cccbb","aacbb","caacc","bcbbb"], words2 = ["c","cc","b"]</span></p>

<p><strong>示例 5:</strong></p>

<pre>
<strong>输入:</strong>words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["ec","oc","ceo"]
<strong>输出:</strong>["facebook","leetcode"]
</pre>
<p><span class="example-io"><b>输出:</b></span><span class="example-io">["cccbb"]</span></p>
</div>

<p>&nbsp;</p>

Expand Down
4 changes: 2 additions & 2 deletions solution/0900-0999/0975.Odd Even Jump/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tags:
<pre>
<strong>Input:</strong> arr = [10,13,12,14,15]
<strong>Output:</strong> 2
<strong>Explanation:</strong>
<strong>Explanation:</strong>
From starting index i = 0, we can make our 1st jump to i = 2 (since arr[2] is the smallest among arr[1], arr[2], arr[3], arr[4] that is greater or equal to arr[0]), then we cannot jump any more.
From starting index i = 1 and i = 2, we can make our 1st jump to i = 3, then we cannot jump any more.
From starting index i = 3, we can make our 1st jump to i = 4, so we have reached the end.
Expand All @@ -54,7 +54,7 @@ jumps.
<pre>
<strong>Input:</strong> arr = [2,3,1,1,4]
<strong>Output:</strong> 3
<strong>Explanation:</strong>
<strong>Explanation:</strong>
From starting index i = 0, we make jumps to i = 1, i = 2, i = 3:
During our 1st jump (odd-numbered), we first jump to i = 1 because arr[1] is the smallest value in [arr[1], arr[2], arr[3], arr[4]] that is greater than or equal to arr[0].
During our 2nd jump (even-numbered), we jump from i = 1 to i = 2 because arr[2] is the largest value in [arr[2], arr[3], arr[4]] that is less than or equal to arr[1]. arr[3] is also the largest value, but 2 is a smaller index, so we can only jump to i = 2 and not i = 3
Expand Down
14 changes: 7 additions & 7 deletions solution/1100-1199/1172.Dinner Plate Stacks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ D.popAtStack(0); // 返回 20。栈的现状为: 4 21
﹈ ﹈ ﹈
D.popAtStack(2); // 返回 21。栈的现状为: 4
&nbsp; 1 &nbsp;3 &nbsp;5
﹈ ﹈ ﹈
﹈ ﹈ ﹈
D.pop() // 返回 5。栈的现状为: 4
&nbsp; 1 &nbsp;3
﹈ ﹈
D.pop() // 返回 4。栈的现状为: 1 3
﹈ ﹈
D.pop() // 返回 3。栈的现状为: 1
&nbsp; 1 &nbsp;3
﹈ ﹈
D.pop() // 返回 4。栈的现状为: 1 3
﹈ ﹈
D.pop() // 返回 3。栈的现状为: 1
D.pop() // 返回 1。现在没有栈。
D.pop() // 返回 -1。仍然没有栈。
</pre>
Expand Down
16 changes: 8 additions & 8 deletions solution/1100-1199/1172.Dinner Plate Stacks/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tags:
<strong>Output</strong>
[null, null, null, null, null, null, 2, null, null, 20, 21, 5, 4, 3, 1, -1]

<strong>Explanation:</strong>
<strong>Explanation:</strong>
DinnerPlates D = DinnerPlates(2); // Initialize with capacity = 2
D.push(1);
D.push(2);
Expand All @@ -65,14 +65,14 @@ D.popAtStack(0); // Returns 20. The stacks are now: 4 21
﹈ ﹈ ﹈
D.popAtStack(2); // Returns 21. The stacks are now: 4
1 3 5
﹈ ﹈ ﹈
﹈ ﹈ ﹈
D.pop() // Returns 5. The stacks are now: 4
1 3
﹈ ﹈
D.pop() // Returns 4. The stacks are now: 1 3
﹈ ﹈
D.pop() // Returns 3. The stacks are now: 1
1 3
﹈ ﹈
D.pop() // Returns 4. The stacks are now: 1 3
﹈ ﹈
D.pop() // Returns 3. The stacks are now: 1
D.pop() // Returns 1. There are no stacks.
D.pop() // Returns -1. There are still no stacks.
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ tweetCounts.recordTweet("tweet3", 0);
tweetCounts.recordTweet("tweet3", 60);
tweetCounts.recordTweet("tweet3", 10); //&nbsp;"tweet3"&nbsp;发布推文的时间分别是&nbsp;0,&nbsp;10&nbsp;和&nbsp;60 。
tweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 59); //&nbsp;返回&nbsp;[2]。统计频率是每分钟(60 秒),因此只有一个有效时间间隔 [0,60&gt;&nbsp;-&nbsp;&gt;&nbsp;2&nbsp;条推文。
tweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 60); //&nbsp;返回&nbsp;[2,1]。统计频率是每分钟(60 秒),因此有两个有效时间间隔&nbsp;<strong>1)</strong>&nbsp;[0,60&gt;&nbsp;-&nbsp;&gt;&nbsp;2&nbsp;条推文,和&nbsp;<strong>2)</strong>&nbsp;[60,61&gt;&nbsp;-&nbsp;&gt;&nbsp;1&nbsp;条推文。
tweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 60); //&nbsp;返回&nbsp;[2,1]。统计频率是每分钟(60 秒),因此有两个有效时间间隔&nbsp;<strong>1)</strong>&nbsp;[0,60&gt;&nbsp;-&nbsp;&gt;&nbsp;2&nbsp;条推文,和&nbsp;<strong>2)</strong>&nbsp;[60,61&gt;&nbsp;-&nbsp;&gt;&nbsp;1&nbsp;条推文。
tweetCounts.recordTweet("tweet3", 120); // "tweet3"&nbsp;发布推文的时间分别是 0, 10, 60 和 120 。
tweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, 210); //&nbsp;返回&nbsp;[4]。统计频率是每小时(3600 秒),因此只有一个有效时间间隔 [0,211&gt;&nbsp;-&nbsp;&gt;&nbsp;4&nbsp;条推文。
</pre>
Expand Down
30 changes: 7 additions & 23 deletions solution/1400-1499/1400.Construct K Palindrome Strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tags:

<!-- description:start -->

<p>给你一个字符串 <code>s</code>&nbsp;和一个整数 <code>k</code>&nbsp;。请你用 <code>s</code>&nbsp;字符串中 <strong>所有字符</strong>&nbsp;构造 <code>k</code>&nbsp;个非空 <strong>回文串</strong>&nbsp;。</p>
<p>给你一个字符串 <code>s</code>&nbsp;和一个整数 <code>k</code>&nbsp;。请你用 <code>s</code>&nbsp;字符串中 <strong>所有字符</strong>&nbsp;构造 <code>k</code>&nbsp;个非空 <span data-keyword="palindrome-string">回文串</span>&nbsp;。</p>

<p>如果你可以用&nbsp;<code>s</code>&nbsp;中所有字符构造&nbsp;<code>k</code>&nbsp;个回文字符串,那么请你返回 <strong>True</strong>&nbsp;,否则返回&nbsp;<strong>False</strong>&nbsp;。</p>

Expand All @@ -30,52 +30,36 @@ tags:
<p><strong>示例 1:</strong></p>

<pre>
<strong>输入:</strong>s = &quot;annabelle&quot;, k = 2
<strong>输入:</strong>s = "annabelle", k = 2
<strong>输出:</strong>true
<strong>解释:</strong>可以用 s 中所有字符构造 2 个回文字符串。
一些可行的构造方案包括:&quot;anna&quot; + &quot;elble&quot;,&quot;anbna&quot; + &quot;elle&quot;,&quot;anellena&quot; + &quot;b&quot;
一些可行的构造方案包括:"anna" + "elble","anbna" + "elle","anellena" + "b"
</pre>

<p><strong>示例 2:</strong></p>

<pre>
<strong>输入:</strong>s = &quot;leetcode&quot;, k = 3
<strong>输入:</strong>s = "leetcode", k = 3
<strong>输出:</strong>false
<strong>解释:</strong>无法用 s 中所有字符构造 3 个回文串。
</pre>

<p><strong>示例 3:</strong></p>

<pre>
<strong>输入:</strong>s = &quot;true&quot;, k = 4
<strong>输入:</strong>s = "true", k = 4
<strong>输出:</strong>true
<strong>解释:</strong>唯一可行的方案是让 s 中每个字符单独构成一个字符串。
</pre>

<p><strong>示例 4:</strong></p>

<pre>
<strong>输入:</strong>s = &quot;yzyzyzyzyzyzyzy&quot;, k = 2
<strong>输出:</strong>true
<strong>解释:</strong>你只需要将所有的 z 放在一个字符串中,所有的 y 放在另一个字符串中。那么两个字符串都是回文串。
</pre>

<p><strong>示例 5:</strong></p>

<pre>
<strong>输入:</strong>s = &quot;cr&quot;, k = 7
<strong>输出:</strong>false
<strong>解释:</strong>我们没有足够的字符去构造 7 个回文串。
</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= s.length &lt;= 10^5</code></li>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s</code>&nbsp;中所有字符都是小写英文字母。</li>
<li><code>1 &lt;= k &lt;= 10^5</code></li>
<li><code>1 &lt;= k &lt;= 10<sup>5</sup></code></li>
</ul>

<!-- description:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ tags:
<p><strong>示例 1:</strong></p>

<pre><strong>输入:</strong>nums = [8,2,4,7], limit = 4
<strong>输出:</strong>2
<strong>输出:</strong>2
<strong>解释:</strong>所有子数组如下:
[8] 最大绝对差 |8-8| = 0 &lt;= 4.
[8,2] 最大绝对差 |8-2| = 6 &gt; 4.
[8,2] 最大绝对差 |8-2| = 6 &gt; 4.
[8,2,4] 最大绝对差 |8-2| = 6 &gt; 4.
[8,2,4,7] 最大绝对差 |8-2| = 6 &gt; 4.
[2] 最大绝对差 |2-2| = 0 &lt;= 4.
[2,4] 最大绝对差 |2-4| = 2 &lt;= 4.
[2,4,7] 最大绝对差 |2-7| = 5 &gt; 4.
[4] 最大绝对差 |4-4| = 0 &lt;= 4.
[4,7] 最大绝对差 |4-7| = 3 &lt;= 4.
[7] 最大绝对差 |7-7| = 0 &lt;= 4.
[7] 最大绝对差 |7-7| = 0 &lt;= 4.
因此,满足题意的最长子数组的长度为 2 。
</pre>

<p><strong>示例 2:</strong></p>

<pre><strong>输入:</strong>nums = [10,1,2,4,7,2], limit = 5
<strong>输出:</strong>4
<strong>输出:</strong>4
<strong>解释:</strong>满足题意的最长子数组是 [2,4,7,2],其最大绝对差 |2-7| = 5 &lt;= 5 。
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ tags:

<pre>
<strong>Input:</strong> nums = [8,2,4,7], limit = 4
<strong>Output:</strong> 2
<strong>Explanation:</strong> All subarrays are:
<strong>Output:</strong> 2
<strong>Explanation:</strong> All subarrays are:
[8] with maximum absolute diff |8-8| = 0 &lt;= 4.
[8,2] with maximum absolute diff |8-2| = 6 &gt; 4.
[8,2] with maximum absolute diff |8-2| = 6 &gt; 4.
[8,2,4] with maximum absolute diff |8-2| = 6 &gt; 4.
[8,2,4,7] with maximum absolute diff |8-2| = 6 &gt; 4.
[2] with maximum absolute diff |2-2| = 0 &lt;= 4.
[2,4] with maximum absolute diff |2-4| = 2 &lt;= 4.
[2,4,7] with maximum absolute diff |2-7| = 5 &gt; 4.
[4] with maximum absolute diff |4-4| = 0 &lt;= 4.
[4,7] with maximum absolute diff |4-7| = 3 &lt;= 4.
[7] with maximum absolute diff |7-7| = 0 &lt;= 4.
[7] with maximum absolute diff |7-7| = 0 &lt;= 4.
Therefore, the size of the longest subarray is 2.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [10,1,2,4,7,2], limit = 5
<strong>Output:</strong> 4
<strong>Output:</strong> 4
<strong>Explanation:</strong> The subarray [2,4,7,2] is the longest since the maximum absolute diff is |2-7| = 5 &lt;= 5.
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ tags:
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/images/load-1.png" style="height: 221px; width: 389px;" /></p>

<pre>
<strong>输入:</strong>k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3]
<strong>输出:</strong>[1]
<strong>输入:</strong>k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3]
<strong>输出:</strong>[1]
<strong>解释:</strong>
所有服务器一开始都是空闲的。
前 3 个请求分别由前 3 台服务器依次处理。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ tags:
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/images/load-1.png" style="width: 389px; height: 221px;" />
<pre>
<strong>Input:</strong> k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3]
<strong>Output:</strong> [1]
<strong>Explanation:</strong>
<strong>Input:</strong> k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3]
<strong>Output:</strong> [1]
<strong>Explanation:</strong>
All of the servers start out available.
The first 3 requests are handled by the first 3 servers in order.
Request 3 comes in. Server 0 is busy, so it&#39;s assigned to the next available server, which is 1.
Expand All @@ -53,7 +53,7 @@ Servers 0 and 2 handled one request each, while server 1 handled two requests. H
<pre>
<strong>Input:</strong> k = 3, arrival = [1,2,3,4], load = [1,2,1,2]
<strong>Output:</strong> [0]
<strong>Explanation:</strong>
<strong>Explanation:</strong>
The first 3 requests are handled by first 3 servers.
Request 3 comes in. It is handled by server 0 since the server is available.
Server 0 handled two requests, while servers 1 and 2 handled one request each. Hence server 0 is the busiest server.
Expand Down
2 changes: 1 addition & 1 deletion solution/1800-1899/1825.Finding MK Average/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tags:
[null, null, null, -1, null, 3, null, null, null, 5]

<strong>解释:</strong>
MKAverage obj = new MKAverage(3, 1);
MKAverage obj = new MKAverage(3, 1);
obj.addElement(3); // 当前元素为 [3]
obj.addElement(1); // 当前元素为 [3,1]
obj.calculateMKAverage(); // 返回 -1 ,因为 m = 3 ,但数据流中只有 2 个元素
Expand Down
2 changes: 1 addition & 1 deletion solution/1800-1899/1825.Finding MK Average/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tags:
[null, null, null, -1, null, 3, null, null, null, 5]

<strong>Explanation</strong>
<code>MKAverage obj = new MKAverage(3, 1);
<code>MKAverage obj = new MKAverage(3, 1);
obj.addElement(3); // current elements are [3]
obj.addElement(1); // current elements are [3,1]
obj.calculateMKAverage(); // return -1, because m = 3 and only 2 elements exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ nc.change(1, 10); // Your container at index 1 will be filled with number 10.
nc.change(3, 10); // Your container at index 3 will be filled with number 10.
nc.change(5, 10); // Your container at index 5 will be filled with number 10.
nc.find(10); // Number 10 is at the indices 1, 2, 3, and 5. Since the smallest index that is filled with 10 is 1, we return 1.
nc.change(1, 20); // Your container at index 1 will be filled with number 20. Note that index 1 was filled with 10 and then replaced with 20.
nc.change(1, 20); // Your container at index 1 will be filled with number 20. Note that index 1 was filled with 10 and then replaced with 20.
nc.find(10); // Number 10 is at the indices 2, 3, and 5. The smallest index that is filled with 10 is 2. Therefore, we return 2.
</pre>

Expand Down
Loading
Loading