Skip to content

feat: update lc problems #4123

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
Mar 3, 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/0200-0299/0262.Trips and Users/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ banned 是一个表示用户是否被禁止的枚举类型,枚举成员为 (

<p><strong>取消率</strong> 的计算方式如下:(被司机或乘客取消的非禁止用户生成的订单数量) / (非禁止用户生成的订单总数)。</p>

<p>编写解决方案找出&nbsp;<code>"2013-10-01"</code><strong>&nbsp;</strong>至&nbsp;<code>"2013-10-03"</code><strong>&nbsp;</strong>期间非禁止用户(<strong>乘客和司机都必须未被禁止</strong>)的取消率。非禁止用户即 banned 为 No 的用户,禁止用户即 banned 为 Yes 的用户。其中取消率 <code>Cancellation Rate</code> 需要四舍五入保留 <strong>两位小数</strong> 。</p>
<p>编写解决方案找出&nbsp;<code>"2013-10-01"</code><strong>&nbsp;</strong>至&nbsp;<code>"2013-10-03"</code><strong>&nbsp;</strong>期间有&nbsp;<strong>至少&nbsp;</strong>一次行程的非禁止用户(<strong>乘客和司机都必须未被禁止</strong>)的 <strong>取消率</strong>。非禁止用户即 banned 为 No 的用户,禁止用户即 banned 为 Yes 的用户。其中取消率 <code>Cancellation Rate</code> 需要四舍五入保留 <strong>两位小数</strong> 。</p>

<p>返回结果表中的数据 <strong>无顺序要求</strong> 。</p>

Expand Down
2 changes: 2 additions & 0 deletions solution/1300-1399/1363.Largest Multiple of Three/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ source: 第 177 场周赛 Q4
tags:
- 贪心
- 数组
- 数学
- 动态规划
- 排序
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ source: Weekly Contest 177 Q4
tags:
- Greedy
- Array
- Math
- Dynamic Programming
- Sorting
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source: 第 178 场周赛 Q1
tags:
- 数组
- 哈希表
- 计数
- 计数排序
- 排序
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source: Weekly Contest 178 Q1
tags:
- Array
- Hash Table
- Counting
- Counting Sort
- Sorting
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ tags:
(1,2,3,4) 4 个帽子的排列方案数为 24 。
</pre>

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

<pre>
<strong>输入:</strong>hats = [[1,2,3],[2,3,5,6],[1,3,7,9],[1,8,9],[2,5,7]]
<strong>输出:</strong>111
</pre>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tags:

<p>Given a 2D integer array <code>hats</code>, where <code>hats[i]</code> is a list of all hats preferred by the <code>i<sup>th</sup></code> person.</p>

<p>Return <em>the number of ways that the <code>n</code> people wear different hats to each other</em>.</p>
<p>Return the number of ways that <code>n</code> people can wear <strong>different</strong> hats from each other.</p>

<p>Since the answer may be too large, return it modulo <code>10<sup>9</sup> + 7</code>.</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ When i=3, nums[i] = 5, and the average of its neighbors is (4+3) / 2 = 3.5.
When i=1, nums[i] = 7, and the average of its neighbors is (9+6) / 2 = 7.5.
When i=2, nums[i] = 6, and the average of its neighbors is (7+2) / 2 = 4.5.
When i=3, nums[i] = 2, and the average of its neighbors is (6+0) / 2 = 3.
</pre>
Note that the original array [6,2,0,9,7] also satisfies the conditions.</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tags:
<pre>
<strong>Input:</strong> word = &quot;abc&quot;
<strong>Output:</strong> 5
<strong>Explanation:
<strong>Explanation:
</strong>The characters are printed as follows:
- Type the character &#39;a&#39; in 1 second since the pointer is initially on &#39;a&#39;.
- Move the pointer clockwise to &#39;b&#39; in 1 second.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tags:
<p>A string <code>s</code> can be partitioned into groups of size <code>k</code> using the following procedure:</p>

<ul>
<li>The first group consists of the first <code>k</code> characters of the string, the second group consists of the next <code>k</code> characters of the string, and so on. Each character can be a part of <strong>exactly one</strong> group.</li>
<li>The first group consists of the first <code>k</code> characters of the string, the second group consists of the next <code>k</code> characters of the string, and so on. Each element can be a part of <strong>exactly one</strong> group.</li>
<li>For the last group, if the string <strong>does not</strong> have <code>k</code> characters remaining, a character <code>fill</code> is used to complete the group.</li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tags:
[null, null, null, 6, null, 8]

<strong>Explanation</strong>
CountIntervals countIntervals = new CountIntervals(); // initialize the object with an empty set of intervals.
CountIntervals countIntervals = new CountIntervals(); // initialize the object with an empty set of intervals.
countIntervals.add(2, 3); // add [2, 3] to the set of intervals.
countIntervals.add(7, 10); // add [7, 10] to the set of intervals.
countIntervals.count(); // return 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tags:
<strong>输入:</strong>s = "abcba", target = "abc"
<strong>输出:</strong>1
<strong>解释:</strong>
选取下标为 0 、1 和 2 的字符,可以形成 "abc" 的 1 个副本。
选取下标为 0 、1 和 2 的字符,可以形成 "abc" 的 1 个副本。
可以形成最多 1 个 "abc" 的副本,所以返回 1 。
注意,尽管下标 3 和 4 分别有额外的 'a' 和 'b' ,但不能重用下标 2 处的 'c' ,所以无法形成 "abc" 的第 2 个副本。
</pre>
Expand Down
2 changes: 1 addition & 1 deletion solution/2200-2299/2296.Design a Text Editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ textEditor.deleteText(4); // 返回 4
// 删除了 4 个字符。
textEditor.addText("practice"); // 当前文本为 "leetpractice|" 。
textEditor.cursorRight(3); // 返回 "etpractice"
// 当前文本为 "leetpractice|".
// 当前文本为 "leetpractice|".
// 光标无法移动到文本以外,所以无法移动。
// "etpractice" 是光标左边的 10 个字符。
textEditor.cursorLeft(8); // 返回 "leet"
Expand Down
8 changes: 4 additions & 4 deletions solution/2200-2299/2296.Design a Text Editor/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ tags:
TextEditor textEditor = new TextEditor(); // The current text is &quot;|&quot;. (The &#39;|&#39; character represents the cursor)
textEditor.addText(&quot;leetcode&quot;); // The current text is &quot;leetcode|&quot;.
textEditor.deleteText(4); // return 4
// The current text is &quot;leet|&quot;.
// The current text is &quot;leet|&quot;.
// 4 characters were deleted.
textEditor.addText(&quot;practice&quot;); // The current text is &quot;leetpractice|&quot;.
textEditor.addText(&quot;practice&quot;); // The current text is &quot;leetpractice|&quot;.
textEditor.cursorRight(3); // return &quot;etpractice&quot;
// The current text is &quot;leetpractice|&quot;.
// The current text is &quot;leetpractice|&quot;.
// The cursor cannot be moved beyond the actual text and thus did not move.
// &quot;etpractice&quot; is the last 10 characters to the left of the cursor.
textEditor.cursorLeft(8); // return &quot;leet&quot;
Expand All @@ -72,7 +72,7 @@ textEditor.deleteText(10); // return 4
// Only 4 characters were deleted.
textEditor.cursorLeft(2); // return &quot;&quot;
// The current text is &quot;|practice&quot;.
// The cursor cannot be moved beyond the actual text and thus did not move.
// The cursor cannot be moved beyond the actual text and thus did not move.
// &quot;&quot; is the last min(10, 0) = 0 characters to the left of the cursor.
textEditor.cursorRight(6); // return &quot;practi&quot;
// The current text is &quot;practi|ce&quot;.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tags:
<pre>
<strong>Input:</strong> grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]
<strong>Output:</strong> true
<strong>Explanation:</strong> Refer to the diagram above.
<strong>Explanation:</strong> Refer to the diagram above.
An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.
Thus, grid is an X-Matrix.
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tags:
<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 4
<strong>Explanation:</strong>
<strong>Explanation:</strong>
Possible arrangements:
1. All plots are empty.
2. A house is placed on one side of the street.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ tags:
<p><code>nums</code>&nbsp;的 <strong>串联值</strong>&nbsp;最初等于 <code>0</code> 。执行下述操作直到&nbsp;<code>nums</code>&nbsp;变为空:</p>

<ul>
<li>如果&nbsp;<code>nums</code>&nbsp;中存在不止一个数字,分别选中 <code>nums</code> 中的第一个元素和最后一个元素,将二者串联得到的值加到&nbsp;<code>nums</code>&nbsp;的 <strong>串联值</strong> 上,然后从&nbsp;<code>nums</code>&nbsp;中删除第一个和最后一个元素。</li>
<li>如果仅存在一个元素,则将该元素的值加到&nbsp;<code>nums</code> 的串联值上,然后删除这个元素。</li>
<li>如果&nbsp;<code>nums</code>&nbsp;的长度大于 1,分别选中 <code>nums</code> 中的第一个元素和最后一个元素,将二者串联得到的值加到&nbsp;<code>nums</code>&nbsp;的 <strong>串联值</strong> 上,然后从&nbsp;<code>nums</code>&nbsp;中删除第一个和最后一个元素。例如,如果&nbsp;<code>nums</code> 是 <code>[1, 2, 4, 5, 6]</code>,将 16 添加到串联值。</li>
<li>如果&nbsp;<code>nums</code>&nbsp;中仅存在一个元素,则将该元素的值加到&nbsp;<code>nums</code> 的串联值上,然后删除这个元素。</li>
</ul>

<p>返回执行完所有操作后<em>&nbsp;</em><code>nums</code> 的串联值。</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ tags:
<p>The <strong>concatenation value</strong> of <code>nums</code> is initially equal to <code>0</code>. Perform this operation until <code>nums</code> becomes empty:</p>

<ul>
<li>If there exists more than one number in <code>nums</code>, pick the first element and last element in <code>nums</code> respectively and add the value of their concatenation to the <strong>concatenation value</strong> of <code>nums</code>, then delete the first and last element from <code>nums</code>.</li>
<li>If one element exists, add its value to the <strong>concatenation value</strong> of <code>nums</code>, then delete it.</li>
<li>If <code>nums</code> has a size greater than one, add the value of the concatenation of the first and the last element to the <strong>concatenation value</strong> of <code>nums</code>, and remove those two elements from <code>nums</code>. For example, if the <code>nums</code> was <code>[1, 2, 4, 5, 6]</code>, add 16 to the <code>concatenation value</code>.</li>
<li>If only one element exists in <code>nums</code>, add its value to the <strong>concatenation value</strong> of <code>nums</code>, then remove it.</li>
</ul>

<p>Return<em> the concatenation value of the <code>nums</code></em>.</p>
<p>Return<em> the concatenation value of <code>nums</code></em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
17 changes: 7 additions & 10 deletions solution/2500-2599/2574.Left and Right Sum Differences/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,32 @@ tags:

<!-- description:start -->

<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ,请你找出一个下标从 <strong>0</strong> 开始的整数数组 <code>answer</code> ,其中:</p>
<p>给你一个下标从 <strong>0</strong> 开始的长度为&nbsp;<code>n</code>&nbsp;的整数数组 <code>nums</code></p>

<ul>
<li><code>answer.length == nums.length</code></li>
<li><code>answer[i] = |leftSum[i] - rightSum[i]|</code></li>
</ul>

<p>其中:</p>
<p>定义两个数组&nbsp;<code>leftSum</code>&nbsp;和&nbsp;<code>rightSum</code>,其中:</p>

<ul>
<li><code>leftSum[i]</code> 是数组 <code>nums</code> 中下标 <code>i</code> 左侧元素之和。如果不存在对应的元素,<code>leftSum[i] = 0</code> 。</li>
<li><code>rightSum[i]</code> 是数组 <code>nums</code> 中下标 <code>i</code> 右侧元素之和。如果不存在对应的元素,<code>rightSum[i] = 0</code> 。</li>
</ul>

<p>返回数组 <code>answer</code> 。</p>
<p>返回长度为&nbsp;<code>n</code> 数组 <code>answer</code>,其中 <code>answer[i] = |leftSum[i] - rightSum[i]|</code>。</p>

<p>&nbsp;</p>

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

<pre><strong>输入:</strong>nums = [10,4,8,3]
<pre>
<strong>输入:</strong>nums = [10,4,8,3]
<strong>输出:</strong>[15,1,11,22]
<strong>解释:</strong>数组 leftSum 为 [0,10,14,22] 且数组 rightSum 为 [15,11,3,0] 。
数组 answer 为 [|0 - 15|,|10 - 11|,|14 - 3|,|22 - 0|] = [15,1,11,22] 。
</pre>

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

<pre><strong>输入:</strong>nums = [1]
<pre>
<strong>输入:</strong>nums = [1]
<strong>输出:</strong>[0]
<strong>解释:</strong>数组 leftSum 为 [0] 且数组 rightSum 为 [0] 。
数组 answer 为 [|0 - 0|] = [0] 。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@ tags:

<!-- description:start -->

<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a <strong>0-indexed </strong>integer array <code>answer</code> where:</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of size <code>n</code>.</p>

<ul>
<li><code>answer.length == nums.length</code>.</li>
<li><code>answer[i] = |leftSum[i] - rightSum[i]|</code>.</li>
</ul>

<p>Where:</p>
<p>Define two arrays <code>leftSum</code> and <code>rightSum</code> where:</p>

<ul>
<li><code>leftSum[i]</code> is the sum of elements to the left of the index <code>i</code> in the array <code>nums</code>. If there is no such element, <code>leftSum[i] = 0</code>.</li>
<li><code>rightSum[i]</code> is the sum of elements to the right of the index <code>i</code> in the array <code>nums</code>. If there is no such element, <code>rightSum[i] = 0</code>.</li>
<li><code>leftSum[i]</code> is the sum of elements to the left of the index <code>i</code> in the array <code>nums</code>. If there is no such element, <code>leftSum[i] = 0</code>.</li>
<li><code>rightSum[i]</code> is the sum of elements to the right of the index <code>i</code> in the array <code>nums</code>. If there is no such element, <code>rightSum[i] = 0</code>.</li>
</ul>

<p>Return <em>the array</em> <code>answer</code>.</p>
<p>Return an integer array <code>answer</code> of size <code>n</code> where <code>answer[i] = |leftSum[i] - rightSum[i]|</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ tags:

<p>You are given an array <code>energy</code> and an integer <code>k</code>. Return the <strong>maximum</strong> possible energy you can gain.</p>

<p><strong>Note</strong> that when you are reach a magician, you <em>must</em> take energy from them, whether it is negative or positive energy.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

Expand Down
Loading