Skip to content
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

feat: update lc problems #2566

Merged
merged 1 commit into from
Apr 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
<p>总共有&nbsp;<code>5</code>&nbsp;个能量不为 0 的子序列:</p>

<ul>
<li>子序列&nbsp;<code>[<em><strong>1</strong></em>,<em><strong>2</strong></em>,<em><strong>3</strong></em>]</code> 有&nbsp;<code>2</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[1,2,<strong><em>3</em></strong>]</code> 和 <code>[<strong><em>1</em></strong>,<strong><em>2</em></strong>,3]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<em><strong>1</strong></em>,2,<em><strong>3</strong></em>]</code>&nbsp;有 <code>1</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[1,2,<strong><em>3</em></strong>]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[1,<em><strong>2</strong></em>,<em><strong>3</strong></em>]</code> 有&nbsp;<code>1</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[1,2,<strong><em>3</em></strong>]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<em><strong>1</strong></em>,<em><strong>2</strong></em>,3]</code>&nbsp;有&nbsp;<code>1</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[<strong><em>1</em></strong>,<strong><em>2</em></strong>,3]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[1,2,<em><strong>3</strong></em>]</code>&nbsp;有&nbsp;<code>1</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[1,2,<strong><em>3</em></strong>]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<u><em><strong>1</strong></em></u>,<u><em><strong>2</strong></em></u>,<u><em><strong>3</strong></em></u>]</code> 有&nbsp;<code>2</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[1,2,<u><strong><em>3</em></strong></u>]</code> 和 <code>[<u><strong><em>1</em></strong></u>,<u><strong><em>2</em></strong></u>,3]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<u><em><strong>1</strong></em></u>,2,<u><em><strong>3</strong></em></u>]</code>&nbsp;有 <code>1</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[1,2,<u><strong><em>3</em></strong></u>]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[1,<u><em><strong>2</strong></em></u>,<u><em><strong>3</strong></em></u>]</code> 有&nbsp;<code>1</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[1,2,<u><strong><em>3</em></strong></u>]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<u><em><strong>1</strong></em></u>,<u><em><strong>2</strong></em></u>,3]</code>&nbsp;有&nbsp;<code>1</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[<u><strong><em>1</em></strong></u>,<u><strong><em>2</em></strong></u>,3]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[1,2,<u><em><strong>3</strong></em></u>]</code>&nbsp;有&nbsp;<code>1</code>&nbsp;个和为&nbsp;<code>3</code>&nbsp;的子序列:<code>[1,2,<u><strong><em>3</em></strong></u>]</code>&nbsp;。</li>
</ul>

<p>所以答案为&nbsp;<code>2 + 1 + 1 + 1 + 1 = 6</code>&nbsp;。</p>
Expand All @@ -52,9 +52,9 @@
<p>总共有&nbsp;<code>3</code>&nbsp;个能量不为 0 的子序列:</p>

<ul>
<li>子序列&nbsp;<code>[<em><strong>2</strong></em>,<em><strong>3</strong></em>,<em><strong>3</strong></em>]</code>&nbsp;有 2 个子序列和为&nbsp;<code>5</code>&nbsp;:<code>[<strong><em>2</em></strong>,3,<strong><em>3</em></strong>]</code> 和&nbsp;<code>[<strong><em>2</em></strong>,<strong><em>3</em></strong>,3]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<em><strong>2</strong></em>,3,<em><strong>3</strong></em>]</code>&nbsp;有 1 个子序列和为&nbsp;<code>5</code>&nbsp;:<code>[<strong><em>2</em></strong>,3,<strong><em>3</em></strong>]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<em><strong>2</strong></em>,<em><strong>3</strong></em>,3]</code>&nbsp;有 1 个子序列和为 <code>5</code>&nbsp;:<code>[<strong><em>2</em></strong>,<strong><em>3</em></strong>,3]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<u><em><strong>2</strong></em></u>,<u><em><strong>3</strong></em></u>,<u><em><strong>3</strong></em></u>]</code>&nbsp;有 2 个子序列和为&nbsp;<code>5</code>&nbsp;:<code>[<u><strong><em>2</em></strong></u>,3,<u><strong><em>3</em></strong></u>]</code> 和&nbsp;<code>[<u><strong><em>2</em></strong></u>,<u><strong><em>3</em></strong></u>,3]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<u><em><strong>2</strong></em></u>,3,<u><em><strong>3</strong></em></u>]</code>&nbsp;有 1 个子序列和为&nbsp;<code>5</code>&nbsp;:<code>[<u><strong><em>2</em></strong></u>,3,<u><strong><em>3</em></strong></u>]</code>&nbsp;。</li>
<li>子序列&nbsp;<code>[<u><em><strong>2</strong></em></u>,<u><em><strong>3</strong></em></u>,3]</code>&nbsp;有 1 个子序列和为 <code>5</code>&nbsp;:<code>[<u><strong><em>2</em></strong></u>,<u><strong><em>3</em></strong></u>,3]</code>&nbsp;。</li>
</ul>

<p>所以答案为&nbsp;<code>2 + 1 + 1 = 4</code>&nbsp;。</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

[English Version](/solution/3100-3199/3104.Find%20Longest%20Self-Contained%20Substring/README_EN.md)

<!-- tags: -->
<!-- tags:哈希表,字符串,二分查找,前缀和 -->

## 题目描述

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

<p>Given a string <code>s</code>, your task is to find the length of the <strong>longest self-contained</strong> <span data-keyword="substring-nonempty">substring</span> of <code>s</code>.</p>

<p>A substring <code>t</code> of a string <code>s</code> is considered <strong>self-contained </strong>if <code>t != s</code> and for every character in <code>t</code>, it doesn&#39;t exist in the <em>rest</em> of <code>s</code>.</p>
<p>A substring <code>t</code> of a string <code>s</code> is called <strong>self-contained </strong>if <code>t != s</code> and for every character in <code>t</code>, it doesn&#39;t exist in the <em>rest</em> of <code>s</code>.</p>

<p>Return the length of the <em>longest<strong> </strong>self-contained </em>substring of <code>s</code> if it exists, otherwise, return -1.</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

[中文文档](/solution/3100-3199/3104.Find%20Longest%20Self-Contained%20Substring/README.md)

<!-- tags: -->
<!-- tags:Hash Table,String,Binary Search,Prefix Sum -->

## Description

<p>Given a string <code>s</code>, your task is to find the length of the <strong>longest self-contained</strong> <span data-keyword="substring-nonempty">substring</span> of <code>s</code>.</p>

<p>A substring <code>t</code> of a string <code>s</code> is considered <strong>self-contained </strong>if <code>t != s</code> and for every character in <code>t</code>, it doesn&#39;t exist in the <em>rest</em> of <code>s</code>.</p>
<p>A substring <code>t</code> of a string <code>s</code> is called <strong>self-contained </strong>if <code>t != s</code> and for every character in <code>t</code>, it doesn&#39;t exist in the <em>rest</em> of <code>s</code>.</p>

<p>Return the length of the <em>longest<strong> </strong>self-contained </em>substring of <code>s</code> if it exists, otherwise, return -1.</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[English Version](/solution/3100-3199/3105.Longest%20Strictly%20Increasing%20or%20Strictly%20Decreasing%20Subarray/README_EN.md)

<!-- tags: -->
<!-- tags:数组 -->

## 题目描述

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[中文文档](/solution/3100-3199/3105.Longest%20Strictly%20Increasing%20or%20Strictly%20Decreasing%20Subarray/README.md)

<!-- tags: -->
<!-- tags:Array -->

## Description

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[English Version](/solution/3100-3199/3106.Lexicographically%20Smallest%20String%20After%20Operations%20With%20Constraint/README_EN.md)

<!-- tags: -->
<!-- tags:贪心,字符串 -->

## 题目描述

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[中文文档](/solution/3100-3199/3106.Lexicographically%20Smallest%20String%20After%20Operations%20With%20Constraint/README.md)

<!-- tags: -->
<!-- tags:Greedy,String -->

## Description

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

[English Version](/solution/3100-3199/3107.Minimum%20Operations%20to%20Make%20Median%20of%20Array%20Equal%20to%20K/README_EN.md)

<!-- tags: -->
<!-- tags:贪心,数组,排序 -->

## 题目描述

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

<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;和一个 <strong>非负</strong>&nbsp;整数&nbsp;<code>k</code>&nbsp;。</p>

<p>一次操作中,你可以选择任一下标&nbsp;<code>i</code>&nbsp;,然后将&nbsp;<code>nums[i]</code>&nbsp;加&nbsp;<code>1</code>&nbsp;或者减&nbsp;<code>1</code>&nbsp;。</p>
<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;和一个 <strong>非负</strong>&nbsp;整数&nbsp;<code>k</code>&nbsp;。一次操作中,你可以选择任一元素&nbsp;加&nbsp;<code>1</code>&nbsp;或者减&nbsp;<code>1</code>&nbsp;。</p>

<p>请你返回将 <code>nums</code>&nbsp;<strong>中位数</strong>&nbsp;变为 <code>k</code>&nbsp;所需要的 <strong>最少</strong>&nbsp;操作次数。</p>

<p>一个数组的 <strong>中位数</strong>&nbsp;指的是数组按 <strong>非递减</strong> 顺序排序后最中间的元素。如果数组长度为偶数,我们选择中间两个数的较大值为中位数。</p>
<p>一个数组的中位数指的是数组按非递减顺序排序后最中间的元素。如果数组长度为偶数,我们选择中间两个数的较大值为中位数。</p>

<p>&nbsp;</p>

Expand All @@ -25,7 +23,7 @@

<p><span class="example-io"><b>输出:</b>2</span></p>

<p><b>解释:</b>我们将&nbsp;<code>nums[1]</code> 和&nbsp;<code>nums[4]</code>&nbsp;减 <code>1</code>&nbsp;得到&nbsp;<code>[2, 4, 6, 8, 4]</code>&nbsp;。现在数组的中位数等于&nbsp;<code>k</code>&nbsp;。所以答案为 2 。</p>
<p><b>解释:</b>我们将&nbsp;<code>nums[1]</code> 和&nbsp;<code>nums[4]</code>&nbsp;减 <code>1</code>&nbsp;得到&nbsp;<code>[2, 4, 6, 8, 4]</code>&nbsp;。现在数组的中位数等于&nbsp;<code>k</code>&nbsp;。</p>
</div>

<p><strong class="example">示例 2:</strong></p>
Expand All @@ -35,7 +33,7 @@

<p><span class="example-io"><b>输出:</b>3</span></p>

<p><b>解释:</b>我们将&nbsp;<code>nums[1]</code>&nbsp;增加 1 两次,并且将&nbsp;<code>nums[2]</code>&nbsp;增加 1 一次,得到&nbsp;<code>[2, 7, 7, 8, 5]</code>&nbsp;。结果数组的中位数等于&nbsp;<code>k</code>&nbsp;。所以答案为 3 。</p>
<p><b>解释:</b>我们将&nbsp;<code>nums[1]</code>&nbsp;增加 1 两次,并且将&nbsp;<code>nums[2]</code>&nbsp;增加 1 一次,得到&nbsp;<code>[2, 7, 7, 8, 5]</code>&nbsp;。</p>
</div>

<p><strong class="example">示例 3:</strong></p>
Expand All @@ -45,7 +43,7 @@

<p><span class="example-io"><b>输出:</b>0</span></p>

<p><b>解释:</b>数组中位数已经等于 <code>k</code>&nbsp;了,所以不需要进行任何操作。</p>
<p><b>解释:</b>数组中位数已经等于 <code>k</code>&nbsp;了。</p>
</div>

<p>&nbsp;</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

[中文文档](/solution/3100-3199/3107.Minimum%20Operations%20to%20Make%20Median%20of%20Array%20Equal%20to%20K/README.md)

<!-- tags: -->
<!-- tags:Greedy,Array,Sorting -->

## Description

<p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. In one operation, you can increase or decrease any element by 1.</p>

<p>Return the <strong>minimum</strong> number of operations needed to make the <strong><span data-keyword="median-array">median</span></strong> of <code>nums</code> <em>equal</em> to <code>k</code>.</p>
<p>Return the <strong>minimum</strong> number of operations needed to make the <strong>median</strong> of <code>nums</code> <em>equal</em> to <code>k</code>.</p>

<p>The median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the larger of the two values is taken.</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 @@ -2,7 +2,7 @@

[English Version](/solution/3100-3199/3108.Minimum%20Cost%20Walk%20in%20Weighted%20Graph/README_EN.md)

<!-- tags: -->
<!-- tags:位运算,并查集,图,数组 -->

## 题目描述

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[中文文档](/solution/3100-3199/3108.Minimum%20Cost%20Walk%20in%20Weighted%20Graph/README.md)

<!-- tags: -->
<!-- tags:Bit Manipulation,Union Find,Graph,Array -->

## Description

Expand Down Expand Up @@ -49,7 +49,7 @@
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= edges.length &lt;= 10<sup>5</sup></code></li>
<li><code>edges[i].length == 3</code></li>
<li><code>0 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt;= n - 1</code></li>
Expand All @@ -58,6 +58,7 @@
<li><code>1 &lt;= query.length &lt;= 10<sup>5</sup></code></li>
<li><code>query[i].length == 2</code></li>
<li><code>0 &lt;= s<sub>i</sub>, t<sub>i</sub> &lt;= n - 1</code></li>
<li><code>s<sub>i</sub> !=&nbsp;t<sub>i</sub></code></li>
</ul>

## Solutions
Expand Down
10 changes: 5 additions & 5 deletions solution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3114,11 +3114,11 @@
| 3101 | [交替子数组计数](/solution/3100-3199/3101.Count%20Alternating%20Subarrays/README.md) | `数组`,`数学` | 中等 | 第 391 场周赛 |
| 3102 | [最小化曼哈顿距离](/solution/3100-3199/3102.Minimize%20Manhattan%20Distances/README.md) | `数组`,`数学` | 困难 | 第 391 场周赛 |
| 3103 | [查找热门话题标签 II](/solution/3100-3199/3103.Find%20Trending%20Hashtags%20II/README.md) | `数据库` | 困难 | 🔒 |
| 3104 | [Find Longest Self-Contained Substring](/solution/3100-3199/3104.Find%20Longest%20Self-Contained%20Substring/README.md) | | 困难 | 🔒 |
| 3105 | [最长的严格递增或递减子数组](/solution/3100-3199/3105.Longest%20Strictly%20Increasing%20or%20Strictly%20Decreasing%20Subarray/README.md) | | 简单 | 第 392 场周赛 |
| 3106 | [满足距离约束且字典序最小的字符串](/solution/3100-3199/3106.Lexicographically%20Smallest%20String%20After%20Operations%20With%20Constraint/README.md) | | 中等 | 第 392 场周赛 |
| 3107 | [使数组中位数等于 K 的最少操作数](/solution/3100-3199/3107.Minimum%20Operations%20to%20Make%20Median%20of%20Array%20Equal%20to%20K/README.md) | | 中等 | 第 392 场周赛 |
| 3108 | [带权图里旅途的最小代价](/solution/3100-3199/3108.Minimum%20Cost%20Walk%20in%20Weighted%20Graph/README.md) | | 困难 | 第 392 场周赛 |
| 3104 | [Find Longest Self-Contained Substring](/solution/3100-3199/3104.Find%20Longest%20Self-Contained%20Substring/README.md) | `哈希表`,`字符串`,`二分查找`,`前缀和` | 困难 | 🔒 |
| 3105 | [最长的严格递增或递减子数组](/solution/3100-3199/3105.Longest%20Strictly%20Increasing%20or%20Strictly%20Decreasing%20Subarray/README.md) | `数组` | 简单 | 第 392 场周赛 |
| 3106 | [满足距离约束且字典序最小的字符串](/solution/3100-3199/3106.Lexicographically%20Smallest%20String%20After%20Operations%20With%20Constraint/README.md) | `贪心`,`字符串` | 中等 | 第 392 场周赛 |
| 3107 | [使数组中位数等于 K 的最少操作数](/solution/3100-3199/3107.Minimum%20Operations%20to%20Make%20Median%20of%20Array%20Equal%20to%20K/README.md) | `贪心`,`数组`,`排序` | 中等 | 第 392 场周赛 |
| 3108 | [带权图里旅途的最小代价](/solution/3100-3199/3108.Minimum%20Cost%20Walk%20in%20Weighted%20Graph/README.md) | `位运算`,`并查集`,`图`,`数组` | 困难 | 第 392 场周赛 |

## 版权

Expand Down
10 changes: 5 additions & 5 deletions solution/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3112,11 +3112,11 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 3101 | [Count Alternating Subarrays](/solution/3100-3199/3101.Count%20Alternating%20Subarrays/README_EN.md) | `Array`,`Math` | Medium | Weekly Contest 391 |
| 3102 | [Minimize Manhattan Distances](/solution/3100-3199/3102.Minimize%20Manhattan%20Distances/README_EN.md) | `Array`,`Math` | Hard | Weekly Contest 391 |
| 3103 | [Find Trending Hashtags II](/solution/3100-3199/3103.Find%20Trending%20Hashtags%20II/README_EN.md) | `Database` | Hard | 🔒 |
| 3104 | [Find Longest Self-Contained Substring](/solution/3100-3199/3104.Find%20Longest%20Self-Contained%20Substring/README_EN.md) | | Hard | 🔒 |
| 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](/solution/3100-3199/3105.Longest%20Strictly%20Increasing%20or%20Strictly%20Decreasing%20Subarray/README_EN.md) | | Easy | Weekly Contest 392 |
| 3106 | [Lexicographically Smallest String After Operations With Constraint](/solution/3100-3199/3106.Lexicographically%20Smallest%20String%20After%20Operations%20With%20Constraint/README_EN.md) | | Medium | Weekly Contest 392 |
| 3107 | [Minimum Operations to Make Median of Array Equal to K](/solution/3100-3199/3107.Minimum%20Operations%20to%20Make%20Median%20of%20Array%20Equal%20to%20K/README_EN.md) | | Medium | Weekly Contest 392 |
| 3108 | [Minimum Cost Walk in Weighted Graph](/solution/3100-3199/3108.Minimum%20Cost%20Walk%20in%20Weighted%20Graph/README_EN.md) | | Hard | Weekly Contest 392 |
| 3104 | [Find Longest Self-Contained Substring](/solution/3100-3199/3104.Find%20Longest%20Self-Contained%20Substring/README_EN.md) | `Hash Table`,`String`,`Binary Search`,`Prefix Sum` | Hard | 🔒 |
| 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](/solution/3100-3199/3105.Longest%20Strictly%20Increasing%20or%20Strictly%20Decreasing%20Subarray/README_EN.md) | `Array` | Easy | Weekly Contest 392 |
| 3106 | [Lexicographically Smallest String After Operations With Constraint](/solution/3100-3199/3106.Lexicographically%20Smallest%20String%20After%20Operations%20With%20Constraint/README_EN.md) | `Greedy`,`String` | Medium | Weekly Contest 392 |
| 3107 | [Minimum Operations to Make Median of Array Equal to K](/solution/3100-3199/3107.Minimum%20Operations%20to%20Make%20Median%20of%20Array%20Equal%20to%20K/README_EN.md) | `Greedy`,`Array`,`Sorting` | Medium | Weekly Contest 392 |
| 3108 | [Minimum Cost Walk in Weighted Graph](/solution/3100-3199/3108.Minimum%20Cost%20Walk%20in%20Weighted%20Graph/README_EN.md) | `Bit Manipulation`,`Union Find`,`Graph`,`Array` | Hard | Weekly Contest 392 |

## Copyright

Expand Down
Loading