Skip to content

chore: update lc problems #4336

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
Apr 8, 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def department_highest_salary(
result = top_earners[['name_y', 'name_x', 'salary']].copy()
result.columns = ['Department', 'Employee', 'Salary']

return result
return result
4 changes: 2 additions & 2 deletions solution/0400-0499/0416.Partition Equal Subset Sum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ impl Solution {
let n = nums.len();
let mut f = vec![vec![false; m + 1]; n + 1];
f[0][0] = true;

for i in 1..=n {
let x = nums[i - 1] as usize;
for j in 0..=m {
f[i][j] = f[i - 1][j] || (j >= x && f[i - 1][j - x]);
}
}

f[n][m]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ impl Solution {
let n = nums.len();
let mut f = vec![vec![false; m + 1]; n + 1];
f[0][0] = true;

for i in 1..=n {
let x = nums[i - 1] as usize;
for j in 0..=m {
f[i][j] = f[i - 1][j] || (j >= x && f[i - 1][j - x]);
}
}

f[n][m]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ impl Solution {
let n = nums.len();
let mut f = vec![vec![false; m + 1]; n + 1];
f[0][0] = true;

for i in 1..=n {
let x = nums[i - 1] as usize;
for j in 0..=m {
f[i][j] = f[i - 1][j] || (j >= x && f[i - 1][j - x]);
}
}

f[n][m]
}
}
2 changes: 1 addition & 1 deletion solution/0700-0799/0752.Open the Lock/Solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def next(s):
s = set(deadends)
if '0000' in s:
return -1
q = deque([('0000')])
q = deque(['0000'])
s.add('0000')
ans = 0
while q:
Expand Down
2 changes: 1 addition & 1 deletion solution/0700-0799/0752.Open the Lock/Solution2.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def extend(m1, m2, q):

def bfs():
m1, m2 = {"0000": 0}, {target: 0}
q1, q2 = deque([('0000')]), deque([(target)])
q1, q2 = deque(['0000']), deque([target])
while q1 and q2:
t = extend(m1, m2, q1) if len(q1) <= len(q2) else extend(m2, m1, q2)
if t != -1:
Expand Down
2 changes: 1 addition & 1 deletion solution/0700-0799/0773.Sliding Puzzle/Solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def f():
if start == end:
return 0
vis = {start}
q = deque([(start)])
q = deque([start])
ans = 0
while q:
ans += 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
This is the custom function interface.
You should not implement it, or speculate about its implementation
class CustomFunction:
# Returns f(x, y) for any given positive integers x and y.
# Note that f(x, y) is increasing with respect to both x and y.
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
def f(self, x, y):
This is the custom function interface.
You should not implement it, or speculate about its implementation
class CustomFunction:
# Returns f(x, y) for any given positive integers x and y.
# Note that f(x, y) is increasing with respect to both x and y.
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
def f(self, x, y):

"""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
This is the custom function interface.
You should not implement it, or speculate about its implementation
class CustomFunction:
# Returns f(x, y) for any given positive integers x and y.
# Note that f(x, y) is increasing with respect to both x and y.
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
def f(self, x, y):
This is the custom function interface.
You should not implement it, or speculate about its implementation
class CustomFunction:
# Returns f(x, y) for any given positive integers x and y.
# Note that f(x, y) is increasing with respect to both x and y.
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
def f(self, x, y):

"""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::collections::HashSet;
impl Solution {
pub fn minimum_operations(nums: Vec<i32>) -> i32 {
let mut s = HashSet::new();
for i in (0..nums.len()).rev() {
if !s.insert(nums[i]) {
return (i / 3) as i32 + 1;
}
}
0
}
}
use std::collections::HashSet;

impl Solution {
pub fn minimum_operations(nums: Vec<i32>) -> i32 {
let mut s = HashSet::new();
for i in (0..nums.len()).rev() {
if !s.insert(nums[i]) {
return (i / 3) as i32 + 1;
}
}
0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3506.Fi

<!-- problem:start -->

# [3506. 查找消除细菌菌株所需时间 II 🔒](https://leetcode.cn/problems/find-time-required-to-eliminate-bacterial-strains)
# [3506. 查找消除细菌菌株所需时间 🔒](https://leetcode.cn/problems/find-time-required-to-eliminate-bacterial-strains)

[English Version](/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains/README_EN.md)

Expand Down
147 changes: 147 additions & 0 deletions solution/3500-3599/3511.Make a Positive Array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3511.Make%20a%20Positive%20Array/README.md
---

<!-- problem:start -->

# [3511. 构造正数组 🔒](https://leetcode.cn/problems/make-a-positive-array)

[English Version](/solution/3500-3599/3511.Make%20a%20Positive%20Array/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给定一个数组&nbsp;<code>nums</code>。一个数组被认为是 <strong>正</strong> 的,如果每个包含 <strong>超过两个</strong> 元素的 <strong><span data-keyword="subarray">子数组</span></strong> 的所有数字之和都是正数。</p>

<p>您可以执行以下操作任意多次:</p>

<ul>
<li>用 -10<sup>18</sup> 和 10<sup>18&nbsp;</sup>之间的任意整数替换&nbsp;<code>nums</code>&nbsp;中的 <strong>一个</strong>&nbsp;元素。</li>
</ul>

<p>找到使 <code>nums</code> 变为正数组所需的最小操作数。</p>

<p>&nbsp;</p>

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

<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [-10,15,-12]</span></p>

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

<p><strong>解释:</strong></p>

<p>唯一有超过 2 个元素的子数组是这个数组本身。所有元素的和是&nbsp;<code>(-10) + 15 + (-12) = -7</code>。通过将&nbsp;<code>nums[0]</code>&nbsp;替换为 0,新的和变为&nbsp;<code>0 + 15 + (-12) = 3</code>。因此,现在数组是正的。</p>
</div>

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

<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [-1,-2,3,-1,2,6]</span></p>

<p><strong>输出:</strong><span class="example-io">1</span></p>

<p><strong>解释:</strong></p>

<p>具有 2 个以上元素且和非正的子数组是:</p>

<table style="border: 1px solid black;">
<tbody>
<tr>
<th style="border: 1px solid black;">子数组下标</th>
<th style="border: 1px solid black;">子数组</th>
<th style="border: 1px solid black;">和</th>
<th style="border: 1px solid black;">替换后的子数组(令 nums[1] = 1)</th>
<th style="border: 1px solid black;">新的和</th>
</tr>
<tr>
<td style="border: 1px solid black;">nums[0...2]</td>
<td style="border: 1px solid black;">[-1, -2, 3]</td>
<td style="border: 1px solid black;">0</td>
<td style="border: 1px solid black;">[-1, 1, 3]</td>
<td style="border: 1px solid black;">3</td>
</tr>
<tr>
<td style="border: 1px solid black;">nums[0...3]</td>
<td style="border: 1px solid black;">[-1, -2, 3, -1]</td>
<td style="border: 1px solid black;">-1</td>
<td style="border: 1px solid black;">[-1, 1, 3, -1]</td>
<td style="border: 1px solid black;">2</td>
</tr>
<tr>
<td style="border: 1px solid black;">nums[1...3]</td>
<td style="border: 1px solid black;">[-2, 3, -1]</td>
<td style="border: 1px solid black;">0</td>
<td style="border: 1px solid black;">[1, 3, -1]</td>
<td style="border: 1px solid black;">3</td>
</tr>
</tbody>
</table>

<p>因此,<code>nums</code>&nbsp;在一次操作后是正的。</p>
</div>

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

<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,3]</span></p>

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

<p><strong>解释:</strong></p>

<p>数组已经是正的,所以不需要操作。</p>
</div>

<p>&nbsp;</p>

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

<ul>
<li><code>3 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Loading
Loading