feat: update lc problems (#3286)

This commit is contained in:
Libin YANG 2024-07-19 17:53:12 +08:00 committed by GitHub
parent da21eee6e4
commit e3780b7b11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 183 additions and 92 deletions

View File

@ -87,7 +87,7 @@ M 1000</pre>
<li>题目数据保证 <code>s</code> 是一个有效的罗马数字,且表示整数在范围 <code>[1, 3999]</code></li>
<li>题目所给测试用例皆符合罗马数字书写规则,不会出现跨位等情况。</li>
<li>IL 和 IM 这样的例子并不符合题目要求49 应该写作 XLIX999 应该写作 CMXCIX 。</li>
<li>关于罗马数字的详尽书写规则,可以参考 <a href="https://b2b.partcommunity.com/community/knowledge/zh_CN/detail/10753/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97#knowledge_article">罗马数字 - Mathematics </a></li>
<li>关于罗马数字的详尽书写规则,可以参考 <a href="https://baike.baidu.com/item/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97/772296">罗马数字 - 百度百科</a></li>
</ul>
<!-- description:end -->

View File

@ -19,22 +19,25 @@ tags:
<p>一条包含字母&nbsp;<code>A-Z</code> 的消息通过以下映射进行了 <strong>编码</strong> </p>
<pre>
'A' -&gt; "1"
'B' -&gt; "2"
...
'Z' -&gt; "26"</pre>
<p><code>"1" -&gt; 'A'<br />
"2" -&gt; 'B'<br />
...<br />
"25" -&gt; 'Y'<br />
"26" -&gt; 'Z'</code></p>
<p><strong>解码</strong> 已编码的消息,所有数字必须基于上述映射的方法,反向映射回字母(可能有多种方法)。例如,<code>"11106"</code> 可以映射为:</p>
<p>然而,在&nbsp;<strong>解码</strong> 已编码的消息时,你意识到有许多不同的方式来解码,因为有些编码被包含在其它编码当中(<code>"2"</code><code>"5"</code><code>"25"</code>)。</p>
<p>例如,<code>"11106"</code> 可以映射为:</p>
<ul>
<li><code>"AAJF"</code> ,将消息分组为 <code>(1 1 10 6)</code></li>
<li><code>"KJF"</code> ,将消息分组为 <code>(11 10 6)</code></li>
<li><code>"AAJF"</code> ,将消息分组为 <code>(1, 1, 10, 6)</code></li>
<li><code>"KJF"</code> ,将消息分组为 <code>(11, 10, 6)</code></li>
<li>消息不能分组为&nbsp; <code>(1, 11, 06)</code> ,因为 <code>"06"</code>&nbsp;不是一个合法编码(只有 "6" 是合法的)。</li>
</ul>
<p>注意,消息不能分组为&nbsp; <code>(1 11 06)</code> ,因为 <code>"06"</code> 不能映射为 <code>"F"</code> ,这是由于 <code>"6"</code><code>"06"</code> 在映射中并不等价</p>
<p>注意,可能存在无法解码的字符串</p>
<p>给你一个只含数字的 <strong>非空 </strong>字符串 <code>s</code> ,请计算并返回 <strong>解码</strong> 方法的 <strong>总数</strong></p>
<p>给你一个只含数字的 <strong>非空 </strong>字符串 <code>s</code> ,请计算并返回 <strong>解码</strong> 方法的 <strong>总数</strong>如果没有合法的方式解码整个字符串,返回 <code>0</code></p>
<p>题目数据保证答案肯定是一个 <strong>32 位</strong> 的整数。</p>

View File

@ -18,49 +18,47 @@ tags:
<!-- description:start -->
<p>在一个 8 x 8 的棋盘上,有一个白色的车(<code>Rook</code>),用字符 <code>&#39;R&#39;</code> 表示。棋盘上还可能存在空方块,白色的象(<code>Bishop</code>)以及黑色的卒(<code>pawn</code>),分别用字符 <code>&#39;.&#39;</code><code>&#39;B&#39;</code><code>&#39;p&#39;</code> 表示。不难看出,大写字符表示的是白棋,小写字符表示的是黑棋</p>
<p>给定一个&nbsp;<code>8 x 8</code> 的棋盘,<strong>只有一个</strong> 白色的车,用字符 <code>'R'</code> 表示。棋盘上还可能存在白色的象&nbsp;<code>'B'</code>&nbsp;以及黑色的卒&nbsp;<code>'p'</code>。空方块用字符 <code>'.'</code>&nbsp;表示</p>
<p>按国际象棋中的规则移动。东,西,南,北四个基本方向任选其一,然后一直向选定的方向移动,直到满足下列四个条件之一:</p>
<p>可以按水平或竖直方向(上,下,左,右)移动任意个方格直到它遇到另一个棋子或棋盘的边界。如果它能够在一次移动中移动到棋子的方格,则能够 <strong>吃掉</strong> 棋子。</p>
<ul>
<li>棋手选择主动停下来。</li>
<li>棋子因到达棋盘的边缘而停下。</li>
<li>棋子移动到某一方格来捕获位于该方格上敌方(黑色)的卒,停在该方格内。</li>
<li>车不能进入/越过已经放有其他友方棋子(白色的象)的方格,停在友方棋子前。</li>
</ul>
<p>注意:车不能穿过其它棋子,比如象和卒。这意味着如果有其它棋子挡住了路径,车就不能够吃掉棋子。</p>
<p>你现在可以控制车移动一次,请你统计有多少敌方的卒处于你的捕获范围内(即,可以被一步捕获的棋子数)</p>
<p>返回白车将能 <strong>吃掉</strong><strong>卒的数量</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0900-0999/0999.Available%20Captures%20for%20Rook/images/1253_example_1_improved.png" style="height: 305px; width: 300px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0900-0999/0999.Available%20Captures%20for%20Rook/images/1253_example_1_improved.png" style="height: 305px; width: 300px;" /></p>
<pre><strong>输入:</strong>[[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;R&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;p&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;]]
<pre>
<strong>输入:</strong>[[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
<strong>输出:</strong>3
<strong>解释:
</strong>在本例中,车能够捕获所有的卒。
</strong>在本例中,车能够吃掉所有的卒。
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0900-0999/0999.Available%20Captures%20for%20Rook/images/1253_example_2_improved.png" style="height: 306px; width: 300px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0900-0999/0999.Available%20Captures%20for%20Rook/images/1253_example_2_improved.png" style="height: 306px; width: 300px;" /></p>
<pre><strong>输入:</strong>[[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;p&quot;,&quot;p&quot;,&quot;p&quot;,&quot;p&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;p&quot;,&quot;p&quot;,&quot;B&quot;,&quot;p&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;p&quot;,&quot;B&quot;,&quot;R&quot;,&quot;B&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;p&quot;,&quot;p&quot;,&quot;B&quot;,&quot;p&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;p&quot;,&quot;p&quot;,&quot;p&quot;,&quot;p&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;]]
<pre>
<strong>输入:</strong>[[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
<strong>输出:</strong>0
<strong>解释:
</strong>象阻止了车捕获任何卒。
</strong>象阻止了车吃掉任何卒。
</pre>
<p><strong>示例 3</strong></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0900-0999/0999.Available%20Captures%20for%20Rook/images/1253_example_3_improved.png" style="height: 305px; width: 300px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0900-0999/0999.Available%20Captures%20for%20Rook/images/1253_example_3_improved.png" style="height: 305px; width: 300px;" /></p>
<pre><strong>输入:</strong>[[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;p&quot;,&quot;p&quot;,&quot;.&quot;,&quot;R&quot;,&quot;.&quot;,&quot;p&quot;,&quot;B&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;B&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;p&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;]]
<pre>
<strong>输入:</strong>[[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]
<strong>输出:</strong>3
<strong>解释: </strong>
车可以捕获位置 b5d6 和 f5 的卒。
车可以吃掉位置 b5d6 和 f5 的卒。
</pre>
<p>&nbsp;</p>
@ -68,9 +66,10 @@ tags:
<p><strong>提示:</strong></p>
<ol>
<li><code>board.length == board[i].length == 8</code></li>
<li><code>board[i][j]</code> 可以是&nbsp;<code>&#39;R&#39;</code><code>&#39;.&#39;</code><code>&#39;B&#39;</code>&nbsp;&nbsp;<code>&#39;p&#39;</code></li>
<li>只有一个格子上存在&nbsp;<code>board[i][j] == &#39;R&#39;</code></li>
<li><code>board.length == 8</code></li>
<li><code>board[i].length == 8</code></li>
<li><code>board[i][j]</code> 可以是&nbsp;<code>'R'</code><code>'.'</code><code>'B'</code>&nbsp;&nbsp;<code>'p'</code></li>
<li>只有一个格子上存在&nbsp;<code>board[i][j] == 'R'</code></li>
</ol>
<!-- description:end -->

View File

@ -5,6 +5,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1700-1799/1788.Ma
tags:
- 贪心
- 数组
- 哈希表
- 前缀和
---
@ -18,7 +19,7 @@ tags:
<!-- description:start -->
<p>有一个花园,有 <code>n</code> 朵花,这些花都有一个用整数表示的美观度。这些花被种在一条线上。给定一个长度为 <code>n</code> 的整数类型数组 <code>flowers</code> ,每一个 <code>flowers[i]</code> 表示第 <code>i</code> 朵花的美观度。</p>
<p>有一个花园,有&nbsp;<code>n</code>&nbsp;朵花,这些花都有一个用整数表示的美观度。这些花被种在一条线上。给定一个长度为 <code>n</code> 的整数类型数组&nbsp;<code>flowers</code>&nbsp;,每一个&nbsp;<code>flowers[i]</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;朵花的美观度。</p>
<p>一个花园满足下列条件时,该花园是<strong>有效</strong>的。</p>
@ -31,29 +32,32 @@ tags:
<p>返回你去除了任意朵花(也可以不去除任意一朵)之后形成的<strong>有效</strong>花园中最大可能的美观度。</p>
<p> </p>
<p>&nbsp;</p>
<p><b>示例 1</b></p>
<p><b class="example">示例 1</b></p>
<pre><strong>输入:</strong> flowers = [1,2,3,1,2]
<pre>
<strong>输入:</strong> flowers = [1,2,3,1,2]
<strong>输出:</strong> 8
<strong>解释:</strong> 你可以修整为有效花园 [2,3,1,2] 来达到总美观度 2 + 3 + 1 + 2 = 8。</pre>
<p><strong>示例 2</strong></p>
<p><strong class="example">示例 2</strong></p>
<pre><strong>输入:</strong> flowers = [100,1,1,-3,1]
<pre>
<strong>输入:</strong> flowers = [100,1,1,-3,1]
<strong>输出:</strong> 3
<strong>解释:</strong> 你可以修整为有效花园 [1,1,1] 来达到总美观度 1 + 1 + 1 = 3。
</pre>
<p><strong>示例 3</strong></p>
<p><strong class="example">示例 3</strong></p>
<pre><strong>输入:</strong> flowers = [-1,-2,0,-1]
<pre>
<strong>输入:</strong> flowers = [-1,-2,0,-1]
<strong>输出:</strong> -2
<strong>解释:</strong> 你可以修整为有效花园 [-1,-1] 来达到总美观度 -1 + -1 = -2。
</pre>
<p> </p>
<p>&nbsp;</p>
<p><b>提示:</b></p>

View File

@ -5,6 +5,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1700-1799/1788.Ma
tags:
- Greedy
- Array
- Hash Table
- Prefix Sum
---

View File

@ -6,8 +6,10 @@ rating: 2502
source: 第 250 场周赛 Q4
tags:
- 位运算
- 深度优先搜索
- 字典树
- 数组
- 哈希表
---
<!-- problem:start -->

View File

@ -6,8 +6,10 @@ rating: 2502
source: Weekly Contest 250 Q4
tags:
- Bit Manipulation
- Depth-First Search
- Trie
- Array
- Hash Table
---
<!-- problem:start -->

View File

@ -8,6 +8,7 @@ tags:
- 贪心
- 哈希表
- 字符串
- 计数
---
<!-- problem:start -->

View File

@ -8,6 +8,7 @@ tags:
- Greedy
- Hash Table
- String
- Counting
---
<!-- problem:start -->

View File

@ -6,8 +6,11 @@ rating: 2023
source: 第 337 场周赛 Q3
tags:
- 数组
- 哈希表
- 数学
- 动态规划
- 回溯
- 组合数学
- 排序
---

View File

@ -6,8 +6,11 @@ rating: 2023
source: Weekly Contest 337 Q3
tags:
- Array
- Hash Table
- Math
- Dynamic Programming
- Backtracking
- Combinatorics
- Sorting
---

View File

@ -4,7 +4,9 @@ difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2600-2699/2638.Count%20the%20Number%20of%20K-Free%20Subsets/README.md
tags:
- 数组
- 数学
- 动态规划
- 组合数学
- 排序
---

View File

@ -4,7 +4,9 @@ difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2600-2699/2638.Count%20the%20Number%20of%20K-Free%20Subsets/README_EN.md
tags:
- Array
- Math
- Dynamic Programming
- Combinatorics
- Sorting
---

View File

@ -19,36 +19,54 @@ tags:
<!-- description:start -->
<p>给你两个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code>&nbsp;,它们分别含有 <code>n</code>&nbsp;<code>m</code>&nbsp;个元素。</p>
<p>请你计算以下两个数值:</p>
<p>给你两个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code>&nbsp;,它们分别含有 <code>n</code>&nbsp;<code>m</code>&nbsp;个元素。请你计算以下两个数值:</p>
<ul>
<li>统计&nbsp;<code>0 &lt;= i &lt; n</code>&nbsp;中的下标&nbsp;<code>i</code>&nbsp;,满足&nbsp;<code>nums1[i]</code>&nbsp;<code>nums2</code>&nbsp;<strong>至少</strong>&nbsp;出现了一次</li>
<li>统计&nbsp;<code>0 &lt;= i &lt; m</code>&nbsp;中的下标&nbsp;<code>i</code>&nbsp;,满足&nbsp;<code>nums2[i]</code>&nbsp;<code>nums1</code>&nbsp;<strong>至少</strong>&nbsp;出现了一次</li>
<li><code>answer1</code>:使得&nbsp;<code>nums1[i]</code>&nbsp;&nbsp;<code>nums2</code>&nbsp;中出现的下标&nbsp;<code>i</code>&nbsp;的数量</li>
<li><code>answer2</code>:使得&nbsp;<code>nums2[i]</code>&nbsp;&nbsp;<code>nums1</code>&nbsp;中出现的下标&nbsp;<code>i</code>&nbsp;的数量</li>
</ul>
<p>请你返回一个长度为 <code>2</code>&nbsp;的整数数组<em>&nbsp;</em><code>answer</code>&nbsp;<strong>按顺序</strong>&nbsp;分别为以上两个数值</p>
<p>返回 <code>[answer1, answer2]</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]
<b>输出:</b>[3,4]
<b>解释:</b>分别计算两个数值:
- nums1 中下标为 1 2 和 3 的元素在 nums2 中至少出现了一次,所以第一个值为 3 。
- nums2 中下标为 0 1 3 和 4 的元素在 nums1 中至少出现了一次,所以第二个值为 4 。
</pre>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums1 = [2,3,2], nums2 = [1,2]</span></p>
<p><strong>输出:</strong><span class="example-io">[2,1]</span></p>
<p><strong>解释:</strong></p>
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/images/3488_find_common_elements_between_two_arrays-t1.gif" style="width: 225px; height: 150px;" /></p>
</div>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>nums1 = [3,4,2,3], nums2 = [1,5]
<b>输出:</b>[0,0]
<b>解释:</b>两个数组中没有公共元素,所以两个值都为 0 。
</pre>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]</span></p>
<p><strong>输出:</strong><span class="example-io">[3,4]</span></p>
<p><strong>解释:</strong></p>
<p><code>nums1</code>&nbsp;中下标在 123 的元素在&nbsp;<code>nums2</code>&nbsp;中也存在。所以&nbsp;<code>answer1</code>&nbsp;&nbsp;3。</p>
<p><code>nums2</code>&nbsp;中下标在 0134 的元素在&nbsp;<code>nums1</code>&nbsp;中也存在。所以&nbsp;<code>answer2</code>&nbsp;为 4。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums1 = [3,4,2,3], nums2 = [1,5]</span></p>
<p><strong>输出:</strong><span class="example-io">[0,0]</span></p>
<p><strong>解释:</strong></p>
<p><code>nums1</code>&nbsp;&nbsp;<code>nums2</code>&nbsp;中没有相同的数字,所以答案是 [0,0]。</p>
</div>
<p>&nbsp;</p>

View File

@ -22,9 +22,9 @@ tags:
<p>给你一个下标从 <strong>0</strong>&nbsp;开始且全是 <strong></strong>&nbsp;整数的数组&nbsp;<code>nums</code>&nbsp;</p>
<p>一次 <b>操作</b>&nbsp;中,如果两个 <strong>相邻</strong>&nbsp;元素在二进制下数位为 <strong>1</strong>&nbsp;的数目 <strong>相同</strong>&nbsp;,那么你可以将这两个元素交换。你可以执行这个操作 <strong>任意次</strong>&nbsp;<strong>也可以 0 次</strong>)。</p>
<p>一次 <b>操作</b>&nbsp;中,如果两个 <strong>相邻</strong>&nbsp;元素在二进制下 <span data-keyword="set-bit">设置位</span> 的数目 <strong>相同</strong>&nbsp;,那么你可以将这两个元素交换。你可以执行这个操作 <strong>任意次</strong>&nbsp;<strong>也可以 0 次</strong>)。</p>
<p>如果你可以使数组变序,请你返回&nbsp;<code>true</code> ,否则返回&nbsp;<code>false</code>&nbsp;</p>
<p>如果你可以使数组变为非降序,请你返回&nbsp;<code>true</code> ,否则返回&nbsp;<code>false</code>&nbsp;</p>
<p>&nbsp;</p>
@ -34,7 +34,7 @@ tags:
<b>输入:</b>nums = [8,4,2,30,15]
<b>输出:</b>true
<b>解释:</b>我们先观察每个元素的二进制表示。 2 4 和 8 分别都只有一个数位为 1 ,分别为 "10" "100" 和 "1000" 。15 和 30 分别有 4 个数位为 1 "1111" 和 "11110" 。
我们可以通过 4 个操作使数组序:
我们可以通过 4 个操作使数组非降序:
- 交换 nums[0] 和 nums[1] 。8 和 4 分别只有 1 个数位为 1 。数组变为 [4,8,2,30,15] 。
- 交换 nums[1] 和 nums[2] 。8 和 2 分别只有 1 个数位为 1 。数组变为 [4,2,8,30,15] 。
- 交换 nums[0] 和 nums[1] 。4 和 2 分别只有 1 个数位为 1 。数组变为 [2,4,8,30,15] 。
@ -48,7 +48,7 @@ tags:
<pre>
<b>输入:</b>nums = [1,2,3,4,5]
<b>输出:</b>true
<b>解释:</b>数组已经是序的,所以我们返回 true 。
<b>解释:</b>数组已经是非降序的,所以我们返回 true 。
</pre>
<p><strong class="example">示例 3</strong></p>
@ -56,7 +56,7 @@ tags:
<pre>
<b>输入:</b>nums = [3,16,8,4,2]
<b>输出:</b>false
<b>解释:</b>无法通过操作使数组变为序。
<b>解释:</b>无法通过操作使数组变为非降序。
</pre>
<p>&nbsp;</p>

View File

@ -4,6 +4,7 @@ difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3205.Maximum%20Array%20Hopping%20Score%20I/README.md
tags:
- 栈
- 贪心
- 数组
- 动态规划
- 单调栈

View File

@ -4,6 +4,7 @@ difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3205.Maximum%20Array%20Hopping%20Score%20I/README_EN.md
tags:
- Stack
- Greedy
- Array
- Dynamic Programming
- Monotonic Stack

View File

@ -2,6 +2,9 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3215.Count%20Triplets%20with%20Even%20XOR%20Set%20Bits%20II/README.md
tags:
- 位运算
- 数组
---
<!-- problem:start -->

View File

@ -2,6 +2,9 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3215.Count%20Triplets%20with%20Even%20XOR%20Set%20Bits%20II/README_EN.md
tags:
- Bit Manipulation
- Array
---
<!-- problem:start -->

View File

@ -2,6 +2,9 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3216.Lexicographically%20Smallest%20String%20After%20a%20Swap/README.md
tags:
- 贪心
- 字符串
---
<!-- problem:start -->

View File

@ -2,6 +2,9 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3216.Lexicographically%20Smallest%20String%20After%20a%20Swap/README_EN.md
tags:
- Greedy
- String
---
<!-- problem:start -->

View File

@ -2,6 +2,10 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3217.Delete%20Nodes%20From%20Linked%20List%20Present%20in%20Array/README.md
tags:
- 数组
- 哈希表
- 链表
---
<!-- problem:start -->

View File

@ -2,6 +2,10 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3217.Delete%20Nodes%20From%20Linked%20List%20Present%20in%20Array/README_EN.md
tags:
- Array
- Hash Table
- Linked List
---
<!-- problem:start -->

View File

@ -2,6 +2,11 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3218.Minimum%20Cost%20for%20Cutting%20Cake%20I/README.md
tags:
- 贪心
- 数组
- 动态规划
- 排序
---
<!-- problem:start -->

View File

@ -2,6 +2,11 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3218.Minimum%20Cost%20for%20Cutting%20Cake%20I/README_EN.md
tags:
- Greedy
- Array
- Dynamic Programming
- Sorting
---
<!-- problem:start -->

View File

@ -2,6 +2,10 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3219.Minimum%20Cost%20for%20Cutting%20Cake%20II/README.md
tags:
- 贪心
- 数组
- 排序
---
<!-- problem:start -->

View File

@ -2,6 +2,10 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3219.Minimum%20Cost%20for%20Cutting%20Cake%20II/README_EN.md
tags:
- Greedy
- Array
- Sorting
---
<!-- problem:start -->

View File

@ -26,7 +26,7 @@ comments: true
## 往期竞赛
#### 第 406 场周赛(2024-07-14 10:30, 90 分钟) 参赛人数 3421
#### 第 406 场周赛(2024-07-14 10:30, 90 分钟) 参赛人数 3422
- [3216. 交换后字典序最小的字符串](/solution/3200-3299/3216.Lexicographically%20Smallest%20String%20After%20a%20Swap/README.md)
- [3217. 从链表中移除在数组中存在的节点](/solution/3200-3299/3217.Delete%20Nodes%20From%20Linked%20List%20Present%20in%20Array/README.md)
@ -173,21 +173,21 @@ comments: true
- [3112. 访问消失节点的最少时间](/solution/3100-3199/3112.Minimum%20Time%20to%20Visit%20Disappearing%20Nodes/README.md)
- [3113. 边界元素是最大值的子数组数目](/solution/3100-3199/3113.Find%20the%20Number%20of%20Subarrays%20Where%20Boundary%20Elements%20Are%20Maximum/README.md)
#### 第 392 场周赛(2024-04-07 10:30, 90 分钟) 参赛人数 3193
#### 第 392 场周赛(2024-04-07 10:30, 90 分钟) 参赛人数 3194
- [3105. 最长的严格递增或递减子数组](/solution/3100-3199/3105.Longest%20Strictly%20Increasing%20or%20Strictly%20Decreasing%20Subarray/README.md)
- [3106. 满足距离约束且字典序最小的字符串](/solution/3100-3199/3106.Lexicographically%20Smallest%20String%20After%20Operations%20With%20Constraint/README.md)
- [3107. 使数组中位数等于 K 的最少操作数](/solution/3100-3199/3107.Minimum%20Operations%20to%20Make%20Median%20of%20Array%20Equal%20to%20K/README.md)
- [3108. 带权图里旅途的最小代价](/solution/3100-3199/3108.Minimum%20Cost%20Walk%20in%20Weighted%20Graph/README.md)
#### 第 391 场周赛(2024-03-31 10:30, 90 分钟) 参赛人数 4180
#### 第 391 场周赛(2024-03-31 10:30, 90 分钟) 参赛人数 4181
- [3099. 哈沙德数](/solution/3000-3099/3099.Harshad%20Number/README.md)
- [3100. 换水问题 II](/solution/3100-3199/3100.Water%20Bottles%20II/README.md)
- [3101. 交替子数组计数](/solution/3100-3199/3101.Count%20Alternating%20Subarrays/README.md)
- [3102. 最小化曼哈顿距离](/solution/3100-3199/3102.Minimize%20Manhattan%20Distances/README.md)
#### 第 127 场双周赛(2024-03-30 22:30, 90 分钟) 参赛人数 2950
#### 第 127 场双周赛(2024-03-30 22:30, 90 分钟) 参赛人数 2951
- [3095. 或值至少 K 的最短子数组 I](/solution/3000-3099/3095.Shortest%20Subarray%20With%20OR%20at%20Least%20K%20I/README.md)
- [3096. 得到更多分数的最少关卡数目](/solution/3000-3099/3096.Minimum%20Levels%20to%20Gain%20More%20Points/README.md)

View File

@ -1798,7 +1798,7 @@
| 1785 | [构成特定和需要添加的最少元素](/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README.md) | `贪心`,`数组` | 中等 | 第 231 场周赛 |
| 1786 | [从第一个节点出发到最后一个节点的受限路径数](/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README.md) | `图`,`拓扑排序`,`动态规划`,`最短路`,`堆(优先队列)` | 中等 | 第 231 场周赛 |
| 1787 | [使所有区间的异或结果为零](/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README.md) | `位运算`,`数组`,`动态规划` | 困难 | 第 231 场周赛 |
| 1788 | [最大化花园的美观度](/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README.md) | `贪心`,`数组`,`前缀和` | 困难 | 🔒 |
| 1788 | [最大化花园的美观度](/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README.md) | `贪心`,`数组`,`哈希表`,`前缀和` | 困难 | 🔒 |
| 1789 | [员工的直属部门](/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README.md) | `数据库` | 简单 | |
| 1790 | [仅执行一次字符串交换能否使两个字符串相等](/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README.md) | `哈希表`,`字符串`,`计数` | 简单 | 第 232 场周赛 |
| 1791 | [找出星型图的中心节点](/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README.md) | `图` | 简单 | 第 232 场周赛 |
@ -1948,7 +1948,7 @@
| 1935 | [可以输入的最大单词数](/solution/1900-1999/1935.Maximum%20Number%20of%20Words%20You%20Can%20Type/README.md) | `哈希表`,`字符串` | 简单 | 第 250 场周赛 |
| 1936 | [新增的最少台阶数](/solution/1900-1999/1936.Add%20Minimum%20Number%20of%20Rungs/README.md) | `贪心`,`数组` | 中等 | 第 250 场周赛 |
| 1937 | [扣分后的最大得分](/solution/1900-1999/1937.Maximum%20Number%20of%20Points%20with%20Cost/README.md) | `数组`,`动态规划` | 中等 | 第 250 场周赛 |
| 1938 | [查询最大基因差](/solution/1900-1999/1938.Maximum%20Genetic%20Difference%20Query/README.md) | `位运算`,`字典树`,`数组` | 困难 | 第 250 场周赛 |
| 1938 | [查询最大基因差](/solution/1900-1999/1938.Maximum%20Genetic%20Difference%20Query/README.md) | `位运算`,`深度优先搜索`,`字典树`,`数组`,`哈希表` | 困难 | 第 250 场周赛 |
| 1939 | [主动请求确认消息的用户](/solution/1900-1999/1939.Users%20That%20Actively%20Request%20Confirmation%20Messages/README.md) | `数据库` | 简单 | 🔒 |
| 1940 | [排序数组之间的最长公共子序列](/solution/1900-1999/1940.Longest%20Common%20Subsequence%20Between%20Sorted%20Arrays/README.md) | `数组`,`哈希表`,`计数` | 中等 | 🔒 |
| 1941 | [检查是否所有字符出现次数相同](/solution/1900-1999/1941.Check%20if%20All%20Characters%20Have%20Equal%20Number%20of%20Occurrences/README.md) | `哈希表`,`字符串`,`计数` | 简单 | 第 57 场双周赛 |
@ -2394,7 +2394,7 @@
| 2381 | [字母移位 II](/solution/2300-2399/2381.Shifting%20Letters%20II/README.md) | `数组`,`字符串`,`前缀和` | 中等 | 第 85 场双周赛 |
| 2382 | [删除操作后的最大子段和](/solution/2300-2399/2382.Maximum%20Segment%20Sum%20After%20Removals/README.md) | `并查集`,`数组`,`有序集合`,`前缀和` | 困难 | 第 85 场双周赛 |
| 2383 | [赢得比赛需要的最少训练时长](/solution/2300-2399/2383.Minimum%20Hours%20of%20Training%20to%20Win%20a%20Competition/README.md) | `贪心`,`数组` | 简单 | 第 307 场周赛 |
| 2384 | [最大回文数字](/solution/2300-2399/2384.Largest%20Palindromic%20Number/README.md) | `贪心`,`哈希表`,`字符串` | 中等 | 第 307 场周赛 |
| 2384 | [最大回文数字](/solution/2300-2399/2384.Largest%20Palindromic%20Number/README.md) | `贪心`,`哈希表`,`字符串`,`计数` | 中等 | 第 307 场周赛 |
| 2385 | [感染二叉树需要的总时间](/solution/2300-2399/2385.Amount%20of%20Time%20for%20Binary%20Tree%20to%20Be%20Infected/README.md) | `树`,`深度优先搜索`,`广度优先搜索`,`哈希表`,`二叉树` | 中等 | 第 307 场周赛 |
| 2386 | [找出数组的第 K 大和](/solution/2300-2399/2386.Find%20the%20K-Sum%20of%20an%20Array/README.md) | `数组`,`排序`,`堆(优先队列)` | 困难 | 第 307 场周赛 |
| 2387 | [行排序矩阵的中位数](/solution/2300-2399/2387.Median%20of%20a%20Row%20Wise%20Sorted%20Matrix/README.md) | `数组`,`二分查找`,`矩阵` | 中等 | 🔒 |
@ -2607,7 +2607,7 @@
| 2594 | [修车的最少时间](/solution/2500-2599/2594.Minimum%20Time%20to%20Repair%20Cars/README.md) | `数组`,`二分查找` | 中等 | 第 100 场双周赛 |
| 2595 | [奇偶位数](/solution/2500-2599/2595.Number%20of%20Even%20and%20Odd%20Bits/README.md) | `位运算` | 简单 | 第 337 场周赛 |
| 2596 | [检查骑士巡视方案](/solution/2500-2599/2596.Check%20Knight%20Tour%20Configuration/README.md) | `深度优先搜索`,`广度优先搜索`,`数组`,`矩阵`,`模拟` | 中等 | 第 337 场周赛 |
| 2597 | [美丽子集的数目](/solution/2500-2599/2597.The%20Number%20of%20Beautiful%20Subsets/README.md) | `数组`,`动态规划`,`回溯`,`排序` | 中等 | 第 337 场周赛 |
| 2597 | [美丽子集的数目](/solution/2500-2599/2597.The%20Number%20of%20Beautiful%20Subsets/README.md) | `数组`,`哈希表`,`数学`,`动态规划`,`回溯`,`组合数学`,`排序` | 中等 | 第 337 场周赛 |
| 2598 | [执行操作后的最大 MEX](/solution/2500-2599/2598.Smallest%20Missing%20Non-negative%20Integer%20After%20Operations/README.md) | `贪心`,`数组`,`哈希表`,`数学` | 中等 | 第 337 场周赛 |
| 2599 | [使前缀和数组非负](/solution/2500-2599/2599.Make%20the%20Prefix%20Sum%20Non-negative/README.md) | `贪心`,`数组`,`堆(优先队列)` | 中等 | 🔒 |
| 2600 | [K 件物品的最大和](/solution/2600-2699/2600.K%20Items%20With%20the%20Maximum%20Sum/README.md) | `贪心`,`数学` | 简单 | 第 338 场周赛 |
@ -2648,7 +2648,7 @@
| 2635 | [转换数组中的每个元素](/solution/2600-2699/2635.Apply%20Transform%20Over%20Each%20Element%20in%20Array/README.md) | | 简单 | |
| 2636 | [Promise 对象池](/solution/2600-2699/2636.Promise%20Pool/README.md) | | 中等 | 🔒 |
| 2637 | [有时间限制的 Promise 对象](/solution/2600-2699/2637.Promise%20Time%20Limit/README.md) | | 中等 | |
| 2638 | [统计 K-Free 子集的总数](/solution/2600-2699/2638.Count%20the%20Number%20of%20K-Free%20Subsets/README.md) | `数组`,`动态规划`,`排序` | 中等 | 🔒 |
| 2638 | [统计 K-Free 子集的总数](/solution/2600-2699/2638.Count%20the%20Number%20of%20K-Free%20Subsets/README.md) | `数组`,`数学`,`动态规划`,`组合数学`,`排序` | 中等 | 🔒 |
| 2639 | [查询网格图中每一列的宽度](/solution/2600-2699/2639.Find%20the%20Width%20of%20Columns%20of%20a%20Grid/README.md) | `数组`,`矩阵` | 简单 | 第 102 场双周赛 |
| 2640 | [一个数组所有前缀的分数](/solution/2600-2699/2640.Find%20the%20Score%20of%20All%20Prefixes%20of%20an%20Array/README.md) | `数组`,`前缀和` | 中等 | 第 102 场双周赛 |
| 2641 | [二叉树的堂兄弟节点 II](/solution/2600-2699/2641.Cousins%20in%20Binary%20Tree%20II/README.md) | `树`,`深度优先搜索`,`广度优先搜索`,`哈希表`,`二叉树` | 中等 | 第 102 场双周赛 |
@ -3215,7 +3215,7 @@
| 3202 | [找出有效子序列的最大长度 II](/solution/3200-3299/3202.Find%20the%20Maximum%20Length%20of%20Valid%20Subsequence%20II/README.md) | `数组`,`动态规划` | 中等 | 第 404 场周赛 |
| 3203 | [合并两棵树后的最小直径](/solution/3200-3299/3203.Find%20Minimum%20Diameter%20After%20Merging%20Two%20Trees/README.md) | `树`,`深度优先搜索`,`广度优先搜索`,`图` | 困难 | 第 404 场周赛 |
| 3204 | [按位用户权限分析](/solution/3200-3299/3204.Bitwise%20User%20Permissions%20Analysis/README.md) | `数据库` | 中等 | 🔒 |
| 3205 | [最大数组跳跃得分 I](/solution/3200-3299/3205.Maximum%20Array%20Hopping%20Score%20I/README.md) | `栈`,`数组`,`动态规划`,`单调栈` | 中等 | 🔒 |
| 3205 | [最大数组跳跃得分 I](/solution/3200-3299/3205.Maximum%20Array%20Hopping%20Score%20I/README.md) | `栈`,`贪心`,`数组`,`动态规划`,`单调栈` | 中等 | 🔒 |
| 3206 | [交替组 I](/solution/3200-3299/3206.Alternating%20Groups%20I/README.md) | `数组`,`滑动窗口` | 简单 | 第 134 场双周赛 |
| 3207 | [与敌人战斗后的最大分数](/solution/3200-3299/3207.Maximum%20Points%20After%20Enemy%20Battles/README.md) | `贪心`,`数组` | 中等 | 第 134 场双周赛 |
| 3208 | [交替组 II](/solution/3200-3299/3208.Alternating%20Groups%20II/README.md) | `数组`,`滑动窗口` | 中等 | 第 134 场双周赛 |
@ -3225,11 +3225,11 @@
| 3212 | [统计 X 和 Y 频数相等的子矩阵数量](/solution/3200-3299/3212.Count%20Submatrices%20With%20Equal%20Frequency%20of%20X%20and%20Y/README.md) | `数组`,`矩阵`,`前缀和` | 中等 | 第 405 场周赛 |
| 3213 | [最小代价构造字符串](/solution/3200-3299/3213.Construct%20String%20with%20Minimum%20Cost/README.md) | `数组`,`字符串`,`动态规划`,`后缀数组` | 困难 | 第 405 场周赛 |
| 3214 | [同比增长率](/solution/3200-3299/3214.Year%20on%20Year%20Growth%20Rate/README.md) | `数据库` | 困难 | 🔒 |
| 3215 | [用偶数异或设置位计数三元组 II](/solution/3200-3299/3215.Count%20Triplets%20with%20Even%20XOR%20Set%20Bits%20II/README.md) | | 中等 | 🔒 |
| 3216 | [交换后字典序最小的字符串](/solution/3200-3299/3216.Lexicographically%20Smallest%20String%20After%20a%20Swap/README.md) | | 简单 | 第 406 场周赛 |
| 3217 | [从链表中移除在数组中存在的节点](/solution/3200-3299/3217.Delete%20Nodes%20From%20Linked%20List%20Present%20in%20Array/README.md) | | 中等 | 第 406 场周赛 |
| 3218 | [切蛋糕的最小总开销 I](/solution/3200-3299/3218.Minimum%20Cost%20for%20Cutting%20Cake%20I/README.md) | | 中等 | 第 406 场周赛 |
| 3219 | [切蛋糕的最小总开销 II](/solution/3200-3299/3219.Minimum%20Cost%20for%20Cutting%20Cake%20II/README.md) | | 困难 | 第 406 场周赛 |
| 3215 | [用偶数异或设置位计数三元组 II](/solution/3200-3299/3215.Count%20Triplets%20with%20Even%20XOR%20Set%20Bits%20II/README.md) | `位运算`,`数组` | 中等 | 🔒 |
| 3216 | [交换后字典序最小的字符串](/solution/3200-3299/3216.Lexicographically%20Smallest%20String%20After%20a%20Swap/README.md) | `贪心`,`字符串` | 简单 | 第 406 场周赛 |
| 3217 | [从链表中移除在数组中存在的节点](/solution/3200-3299/3217.Delete%20Nodes%20From%20Linked%20List%20Present%20in%20Array/README.md) | `数组`,`哈希表`,`链表` | 中等 | 第 406 场周赛 |
| 3218 | [切蛋糕的最小总开销 I](/solution/3200-3299/3218.Minimum%20Cost%20for%20Cutting%20Cake%20I/README.md) | `贪心`,`数组`,`动态规划`,`排序` | 中等 | 第 406 场周赛 |
| 3219 | [切蛋糕的最小总开销 II](/solution/3200-3299/3219.Minimum%20Cost%20for%20Cutting%20Cake%20II/README.md) | `贪心`,`数组`,`排序` | 困难 | 第 406 场周赛 |
| 3220 | [Odd and Even Transactions](/solution/3200-3299/3220.Odd%20and%20Even%20Transactions/README.md) | | 中等 | |
| 3221 | [Maximum Array Hopping Score II](/solution/3200-3299/3221.Maximum%20Array%20Hopping%20Score%20II/README.md) | | 中等 | 🔒 |

View File

@ -1796,7 +1796,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 1785 | [Minimum Elements to Add to Form a Given Sum](/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README_EN.md) | `Greedy`,`Array` | Medium | Weekly Contest 231 |
| 1786 | [Number of Restricted Paths From First to Last Node](/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README_EN.md) | `Graph`,`Topological Sort`,`Dynamic Programming`,`Shortest Path`,`Heap (Priority Queue)` | Medium | Weekly Contest 231 |
| 1787 | [Make the XOR of All Segments Equal to Zero](/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README_EN.md) | `Bit Manipulation`,`Array`,`Dynamic Programming` | Hard | Weekly Contest 231 |
| 1788 | [Maximize the Beauty of the Garden](/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README_EN.md) | `Greedy`,`Array`,`Prefix Sum` | Hard | 🔒 |
| 1788 | [Maximize the Beauty of the Garden](/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README_EN.md) | `Greedy`,`Array`,`Hash Table`,`Prefix Sum` | Hard | 🔒 |
| 1789 | [Primary Department for Each Employee](/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README_EN.md) | `Database` | Easy | |
| 1790 | [Check if One String Swap Can Make Strings Equal](/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README_EN.md) | `Hash Table`,`String`,`Counting` | Easy | Weekly Contest 232 |
| 1791 | [Find Center of Star Graph](/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README_EN.md) | `Graph` | Easy | Weekly Contest 232 |
@ -1946,7 +1946,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 1935 | [Maximum Number of Words You Can Type](/solution/1900-1999/1935.Maximum%20Number%20of%20Words%20You%20Can%20Type/README_EN.md) | `Hash Table`,`String` | Easy | Weekly Contest 250 |
| 1936 | [Add Minimum Number of Rungs](/solution/1900-1999/1936.Add%20Minimum%20Number%20of%20Rungs/README_EN.md) | `Greedy`,`Array` | Medium | Weekly Contest 250 |
| 1937 | [Maximum Number of Points with Cost](/solution/1900-1999/1937.Maximum%20Number%20of%20Points%20with%20Cost/README_EN.md) | `Array`,`Dynamic Programming` | Medium | Weekly Contest 250 |
| 1938 | [Maximum Genetic Difference Query](/solution/1900-1999/1938.Maximum%20Genetic%20Difference%20Query/README_EN.md) | `Bit Manipulation`,`Trie`,`Array` | Hard | Weekly Contest 250 |
| 1938 | [Maximum Genetic Difference Query](/solution/1900-1999/1938.Maximum%20Genetic%20Difference%20Query/README_EN.md) | `Bit Manipulation`,`Depth-First Search`,`Trie`,`Array`,`Hash Table` | Hard | Weekly Contest 250 |
| 1939 | [Users That Actively Request Confirmation Messages](/solution/1900-1999/1939.Users%20That%20Actively%20Request%20Confirmation%20Messages/README_EN.md) | `Database` | Easy | 🔒 |
| 1940 | [Longest Common Subsequence Between Sorted Arrays](/solution/1900-1999/1940.Longest%20Common%20Subsequence%20Between%20Sorted%20Arrays/README_EN.md) | `Array`,`Hash Table`,`Counting` | Medium | 🔒 |
| 1941 | [Check if All Characters Have Equal Number of Occurrences](/solution/1900-1999/1941.Check%20if%20All%20Characters%20Have%20Equal%20Number%20of%20Occurrences/README_EN.md) | `Hash Table`,`String`,`Counting` | Easy | Biweekly Contest 57 |
@ -2392,7 +2392,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 2381 | [Shifting Letters II](/solution/2300-2399/2381.Shifting%20Letters%20II/README_EN.md) | `Array`,`String`,`Prefix Sum` | Medium | Biweekly Contest 85 |
| 2382 | [Maximum Segment Sum After Removals](/solution/2300-2399/2382.Maximum%20Segment%20Sum%20After%20Removals/README_EN.md) | `Union Find`,`Array`,`Ordered Set`,`Prefix Sum` | Hard | Biweekly Contest 85 |
| 2383 | [Minimum Hours of Training to Win a Competition](/solution/2300-2399/2383.Minimum%20Hours%20of%20Training%20to%20Win%20a%20Competition/README_EN.md) | `Greedy`,`Array` | Easy | Weekly Contest 307 |
| 2384 | [Largest Palindromic Number](/solution/2300-2399/2384.Largest%20Palindromic%20Number/README_EN.md) | `Greedy`,`Hash Table`,`String` | Medium | Weekly Contest 307 |
| 2384 | [Largest Palindromic Number](/solution/2300-2399/2384.Largest%20Palindromic%20Number/README_EN.md) | `Greedy`,`Hash Table`,`String`,`Counting` | Medium | Weekly Contest 307 |
| 2385 | [Amount of Time for Binary Tree to Be Infected](/solution/2300-2399/2385.Amount%20of%20Time%20for%20Binary%20Tree%20to%20Be%20Infected/README_EN.md) | `Tree`,`Depth-First Search`,`Breadth-First Search`,`Hash Table`,`Binary Tree` | Medium | Weekly Contest 307 |
| 2386 | [Find the K-Sum of an Array](/solution/2300-2399/2386.Find%20the%20K-Sum%20of%20an%20Array/README_EN.md) | `Array`,`Sorting`,`Heap (Priority Queue)` | Hard | Weekly Contest 307 |
| 2387 | [Median of a Row Wise Sorted Matrix](/solution/2300-2399/2387.Median%20of%20a%20Row%20Wise%20Sorted%20Matrix/README_EN.md) | `Array`,`Binary Search`,`Matrix` | Medium | 🔒 |
@ -2605,7 +2605,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 2594 | [Minimum Time to Repair Cars](/solution/2500-2599/2594.Minimum%20Time%20to%20Repair%20Cars/README_EN.md) | `Array`,`Binary Search` | Medium | Biweekly Contest 100 |
| 2595 | [Number of Even and Odd Bits](/solution/2500-2599/2595.Number%20of%20Even%20and%20Odd%20Bits/README_EN.md) | `Bit Manipulation` | Easy | Weekly Contest 337 |
| 2596 | [Check Knight Tour Configuration](/solution/2500-2599/2596.Check%20Knight%20Tour%20Configuration/README_EN.md) | `Depth-First Search`,`Breadth-First Search`,`Array`,`Matrix`,`Simulation` | Medium | Weekly Contest 337 |
| 2597 | [The Number of Beautiful Subsets](/solution/2500-2599/2597.The%20Number%20of%20Beautiful%20Subsets/README_EN.md) | `Array`,`Dynamic Programming`,`Backtracking`,`Sorting` | Medium | Weekly Contest 337 |
| 2597 | [The Number of Beautiful Subsets](/solution/2500-2599/2597.The%20Number%20of%20Beautiful%20Subsets/README_EN.md) | `Array`,`Hash Table`,`Math`,`Dynamic Programming`,`Backtracking`,`Combinatorics`,`Sorting` | Medium | Weekly Contest 337 |
| 2598 | [Smallest Missing Non-negative Integer After Operations](/solution/2500-2599/2598.Smallest%20Missing%20Non-negative%20Integer%20After%20Operations/README_EN.md) | `Greedy`,`Array`,`Hash Table`,`Math` | Medium | Weekly Contest 337 |
| 2599 | [Make the Prefix Sum Non-negative](/solution/2500-2599/2599.Make%20the%20Prefix%20Sum%20Non-negative/README_EN.md) | `Greedy`,`Array`,`Heap (Priority Queue)` | Medium | 🔒 |
| 2600 | [K Items With the Maximum Sum](/solution/2600-2699/2600.K%20Items%20With%20the%20Maximum%20Sum/README_EN.md) | `Greedy`,`Math` | Easy | Weekly Contest 338 |
@ -2646,7 +2646,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 2635 | [Apply Transform Over Each Element in Array](/solution/2600-2699/2635.Apply%20Transform%20Over%20Each%20Element%20in%20Array/README_EN.md) | | Easy | |
| 2636 | [Promise Pool](/solution/2600-2699/2636.Promise%20Pool/README_EN.md) | | Medium | 🔒 |
| 2637 | [Promise Time Limit](/solution/2600-2699/2637.Promise%20Time%20Limit/README_EN.md) | | Medium | |
| 2638 | [Count the Number of K-Free Subsets](/solution/2600-2699/2638.Count%20the%20Number%20of%20K-Free%20Subsets/README_EN.md) | `Array`,`Dynamic Programming`,`Sorting` | Medium | 🔒 |
| 2638 | [Count the Number of K-Free Subsets](/solution/2600-2699/2638.Count%20the%20Number%20of%20K-Free%20Subsets/README_EN.md) | `Array`,`Math`,`Dynamic Programming`,`Combinatorics`,`Sorting` | Medium | 🔒 |
| 2639 | [Find the Width of Columns of a Grid](/solution/2600-2699/2639.Find%20the%20Width%20of%20Columns%20of%20a%20Grid/README_EN.md) | `Array`,`Matrix` | Easy | Biweekly Contest 102 |
| 2640 | [Find the Score of All Prefixes of an Array](/solution/2600-2699/2640.Find%20the%20Score%20of%20All%20Prefixes%20of%20an%20Array/README_EN.md) | `Array`,`Prefix Sum` | Medium | Biweekly Contest 102 |
| 2641 | [Cousins in Binary Tree II](/solution/2600-2699/2641.Cousins%20in%20Binary%20Tree%20II/README_EN.md) | `Tree`,`Depth-First Search`,`Breadth-First Search`,`Hash Table`,`Binary Tree` | Medium | Biweekly Contest 102 |
@ -3213,7 +3213,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 3202 | [Find the Maximum Length of Valid Subsequence II](/solution/3200-3299/3202.Find%20the%20Maximum%20Length%20of%20Valid%20Subsequence%20II/README_EN.md) | `Array`,`Dynamic Programming` | Medium | Weekly Contest 404 |
| 3203 | [Find Minimum Diameter After Merging Two Trees](/solution/3200-3299/3203.Find%20Minimum%20Diameter%20After%20Merging%20Two%20Trees/README_EN.md) | `Tree`,`Depth-First Search`,`Breadth-First Search`,`Graph` | Hard | Weekly Contest 404 |
| 3204 | [Bitwise User Permissions Analysis](/solution/3200-3299/3204.Bitwise%20User%20Permissions%20Analysis/README_EN.md) | `Database` | Medium | 🔒 |
| 3205 | [Maximum Array Hopping Score I](/solution/3200-3299/3205.Maximum%20Array%20Hopping%20Score%20I/README_EN.md) | `Stack`,`Array`,`Dynamic Programming`,`Monotonic Stack` | Medium | 🔒 |
| 3205 | [Maximum Array Hopping Score I](/solution/3200-3299/3205.Maximum%20Array%20Hopping%20Score%20I/README_EN.md) | `Stack`,`Greedy`,`Array`,`Dynamic Programming`,`Monotonic Stack` | Medium | 🔒 |
| 3206 | [Alternating Groups I](/solution/3200-3299/3206.Alternating%20Groups%20I/README_EN.md) | `Array`,`Sliding Window` | Easy | Biweekly Contest 134 |
| 3207 | [Maximum Points After Enemy Battles](/solution/3200-3299/3207.Maximum%20Points%20After%20Enemy%20Battles/README_EN.md) | `Greedy`,`Array` | Medium | Biweekly Contest 134 |
| 3208 | [Alternating Groups II](/solution/3200-3299/3208.Alternating%20Groups%20II/README_EN.md) | `Array`,`Sliding Window` | Medium | Biweekly Contest 134 |
@ -3223,11 +3223,11 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 3212 | [Count Submatrices With Equal Frequency of X and Y](/solution/3200-3299/3212.Count%20Submatrices%20With%20Equal%20Frequency%20of%20X%20and%20Y/README_EN.md) | `Array`,`Matrix`,`Prefix Sum` | Medium | Weekly Contest 405 |
| 3213 | [Construct String with Minimum Cost](/solution/3200-3299/3213.Construct%20String%20with%20Minimum%20Cost/README_EN.md) | `Array`,`String`,`Dynamic Programming`,`Suffix Array` | Hard | Weekly Contest 405 |
| 3214 | [Year on Year Growth Rate](/solution/3200-3299/3214.Year%20on%20Year%20Growth%20Rate/README_EN.md) | `Database` | Hard | 🔒 |
| 3215 | [Count Triplets with Even XOR Set Bits II](/solution/3200-3299/3215.Count%20Triplets%20with%20Even%20XOR%20Set%20Bits%20II/README_EN.md) | | Medium | 🔒 |
| 3216 | [Lexicographically Smallest String After a Swap](/solution/3200-3299/3216.Lexicographically%20Smallest%20String%20After%20a%20Swap/README_EN.md) | | Easy | Weekly Contest 406 |
| 3217 | [Delete Nodes From Linked List Present in Array](/solution/3200-3299/3217.Delete%20Nodes%20From%20Linked%20List%20Present%20in%20Array/README_EN.md) | | Medium | Weekly Contest 406 |
| 3218 | [Minimum Cost for Cutting Cake I](/solution/3200-3299/3218.Minimum%20Cost%20for%20Cutting%20Cake%20I/README_EN.md) | | Medium | Weekly Contest 406 |
| 3219 | [Minimum Cost for Cutting Cake II](/solution/3200-3299/3219.Minimum%20Cost%20for%20Cutting%20Cake%20II/README_EN.md) | | Hard | Weekly Contest 406 |
| 3215 | [Count Triplets with Even XOR Set Bits II](/solution/3200-3299/3215.Count%20Triplets%20with%20Even%20XOR%20Set%20Bits%20II/README_EN.md) | `Bit Manipulation`,`Array` | Medium | 🔒 |
| 3216 | [Lexicographically Smallest String After a Swap](/solution/3200-3299/3216.Lexicographically%20Smallest%20String%20After%20a%20Swap/README_EN.md) | `Greedy`,`String` | Easy | Weekly Contest 406 |
| 3217 | [Delete Nodes From Linked List Present in Array](/solution/3200-3299/3217.Delete%20Nodes%20From%20Linked%20List%20Present%20in%20Array/README_EN.md) | `Array`,`Hash Table`,`Linked List` | Medium | Weekly Contest 406 |
| 3218 | [Minimum Cost for Cutting Cake I](/solution/3200-3299/3218.Minimum%20Cost%20for%20Cutting%20Cake%20I/README_EN.md) | `Greedy`,`Array`,`Dynamic Programming`,`Sorting` | Medium | Weekly Contest 406 |
| 3219 | [Minimum Cost for Cutting Cake II](/solution/3200-3299/3219.Minimum%20Cost%20for%20Cutting%20Cake%20II/README_EN.md) | `Greedy`,`Array`,`Sorting` | Hard | Weekly Contest 406 |
| 3220 | [Odd and Even Transactions](/solution/3200-3299/3220.Odd%20and%20Even%20Transactions/README_EN.md) | | Medium | |
| 3221 | [Maximum Array Hopping Score II](/solution/3200-3299/3221.Maximum%20Array%20Hopping%20Score%20II/README_EN.md) | | Medium | 🔒 |

File diff suppressed because one or more lines are too long

View File

@ -299,7 +299,16 @@ class Contest:
def get_data(self, retry: int = 3):
try:
res = requests.get(self.contest_url, timeout=6, verify=False).json()
print(self.contest_url)
headers = {
'User-Agent': user_agent,
'Host': 'leetcode.cn',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
}
res = requests.get(
self.contest_url, timeout=6, verify=False, headers=headers
)
res = res.json()
if not res or "error" in res or not res["questions"]:
return {}
questions = res["questions"]
@ -360,6 +369,7 @@ def get_contests(fetch_new=True) -> List:
if c.contest_title_slug in d:
continue
contest_data = c.get_data(retry=10)
time.sleep(1)
if not contest_data:
cnt += 1
if cnt > 2: