Skip to content

Commit 1bc9bd3

Browse files
authored
chore: update lc problems (doocs#4336)
1 parent 2e5b60f commit 1bc9bd3

File tree

15 files changed

+333
-39
lines changed

15 files changed

+333
-39
lines changed

solution/0100-0199/0184.Department Highest Salary/Solution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def department_highest_salary(
1717
result = top_earners[['name_y', 'name_x', 'salary']].copy()
1818
result.columns = ['Department', 'Employee', 'Salary']
1919

20-
return result
20+
return result

solution/0400-0499/0416.Partition Equal Subset Sum/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@ impl Solution {
202202
let n = nums.len();
203203
let mut f = vec![vec![false; m + 1]; n + 1];
204204
f[0][0] = true;
205-
205+
206206
for i in 1..=n {
207207
let x = nums[i - 1] as usize;
208208
for j in 0..=m {
209209
f[i][j] = f[i - 1][j] || (j >= x && f[i - 1][j - x]);
210210
}
211211
}
212-
212+
213213
f[n][m]
214214
}
215215
}

solution/0400-0499/0416.Partition Equal Subset Sum/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ impl Solution {
201201
let n = nums.len();
202202
let mut f = vec![vec![false; m + 1]; n + 1];
203203
f[0][0] = true;
204-
204+
205205
for i in 1..=n {
206206
let x = nums[i - 1] as usize;
207207
for j in 0..=m {
208208
f[i][j] = f[i - 1][j] || (j >= x && f[i - 1][j - x]);
209209
}
210210
}
211-
211+
212212
f[n][m]
213213
}
214214
}

solution/0400-0499/0416.Partition Equal Subset Sum/Solution.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ impl Solution {
88
let n = nums.len();
99
let mut f = vec![vec![false; m + 1]; n + 1];
1010
f[0][0] = true;
11-
11+
1212
for i in 1..=n {
1313
let x = nums[i - 1] as usize;
1414
for j in 0..=m {
1515
f[i][j] = f[i - 1][j] || (j >= x && f[i - 1][j - x]);
1616
}
1717
}
18-
18+
1919
f[n][m]
2020
}
2121
}

solution/0700-0799/0752.Open the Lock/Solution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def next(s):
1717
s = set(deadends)
1818
if '0000' in s:
1919
return -1
20-
q = deque([('0000')])
20+
q = deque(['0000'])
2121
s.add('0000')
2222
ans = 0
2323
while q:

solution/0700-0799/0752.Open the Lock/Solution2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def extend(m1, m2, q):
2727

2828
def bfs():
2929
m1, m2 = {"0000": 0}, {target: 0}
30-
q1, q2 = deque([('0000')]), deque([(target)])
30+
q1, q2 = deque(['0000']), deque([target])
3131
while q1 and q2:
3232
t = extend(m1, m2, q1) if len(q1) <= len(q2) else extend(m2, m1, q2)
3333
if t != -1:

solution/0700-0799/0773.Sliding Puzzle/Solution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def f():
2929
if start == end:
3030
return 0
3131
vis = {start}
32-
q = deque([(start)])
32+
q = deque([start])
3333
ans = 0
3434
while q:
3535
ans += 1

solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/Solution.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
This is the custom function interface.
3-
You should not implement it, or speculate about its implementation
4-
class CustomFunction:
5-
# Returns f(x, y) for any given positive integers x and y.
6-
# Note that f(x, y) is increasing with respect to both x and y.
7-
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
8-
def f(self, x, y):
2+
This is the custom function interface.
3+
You should not implement it, or speculate about its implementation
4+
class CustomFunction:
5+
# Returns f(x, y) for any given positive integers x and y.
6+
# Note that f(x, y) is increasing with respect to both x and y.
7+
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
8+
def f(self, x, y):
99
1010
"""
1111

solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/Solution2.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
This is the custom function interface.
3-
You should not implement it, or speculate about its implementation
4-
class CustomFunction:
5-
# Returns f(x, y) for any given positive integers x and y.
6-
# Note that f(x, y) is increasing with respect to both x and y.
7-
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
8-
def f(self, x, y):
2+
This is the custom function interface.
3+
You should not implement it, or speculate about its implementation
4+
class CustomFunction:
5+
# Returns f(x, y) for any given positive integers x and y.
6+
# Note that f(x, y) is increasing with respect to both x and y.
7+
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
8+
def f(self, x, y):
99
1010
"""
1111

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use std::collections::HashSet;
2-
3-
impl Solution {
4-
pub fn minimum_operations(nums: Vec<i32>) -> i32 {
5-
let mut s = HashSet::new();
6-
for i in (0..nums.len()).rev() {
7-
if !s.insert(nums[i]) {
8-
return (i / 3) as i32 + 1;
9-
}
10-
}
11-
0
12-
}
13-
}
1+
use std::collections::HashSet;
2+
3+
impl Solution {
4+
pub fn minimum_operations(nums: Vec<i32>) -> i32 {
5+
let mut s = HashSet::new();
6+
for i in (0..nums.len()).rev() {
7+
if !s.insert(nums[i]) {
8+
return (i / 3) as i32 + 1;
9+
}
10+
}
11+
0
12+
}
13+
}

solution/3500-3599/3506.Find Time Required to Eliminate Bacterial Strains/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3506.Fi
66

77
<!-- problem:start -->
88

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

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3511.Make%20a%20Positive%20Array/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3511. 构造正数组 🔒](https://leetcode.cn/problems/make-a-positive-array)
10+
11+
[English Version](/solution/3500-3599/3511.Make%20a%20Positive%20Array/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给定一个数组&nbsp;<code>nums</code>。一个数组被认为是 <strong>正</strong> 的,如果每个包含 <strong>超过两个</strong> 元素的 <strong><span data-keyword="subarray">子数组</span></strong> 的所有数字之和都是正数。</p>
18+
19+
<p>您可以执行以下操作任意多次:</p>
20+
21+
<ul>
22+
<li>用 -10<sup>18</sup> 和 10<sup>18&nbsp;</sup>之间的任意整数替换&nbsp;<code>nums</code>&nbsp;中的 <strong>一个</strong>&nbsp;元素。</li>
23+
</ul>
24+
25+
<p>找到使 <code>nums</code> 变为正数组所需的最小操作数。</p>
26+
27+
<p>&nbsp;</p>
28+
29+
<p><strong class="example">示例 1:</strong></p>
30+
31+
<div class="example-block">
32+
<p><span class="example-io"><b>输入:</b>nums = [-10,15,-12]</span></p>
33+
34+
<p><span class="example-io"><b>输出:</b>1</span></p>
35+
36+
<p><strong>解释:</strong></p>
37+
38+
<p>唯一有超过 2 个元素的子数组是这个数组本身。所有元素的和是&nbsp;<code>(-10) + 15 + (-12) = -7</code>。通过将&nbsp;<code>nums[0]</code>&nbsp;替换为 0,新的和变为&nbsp;<code>0 + 15 + (-12) = 3</code>。因此,现在数组是正的。</p>
39+
</div>
40+
41+
<p><strong class="example">示例 2:</strong></p>
42+
43+
<div class="example-block">
44+
<p><span class="example-io"><b>输入:</b>nums = [-1,-2,3,-1,2,6]</span></p>
45+
46+
<p><strong>输出:</strong><span class="example-io">1</span></p>
47+
48+
<p><strong>解释:</strong></p>
49+
50+
<p>具有 2 个以上元素且和非正的子数组是:</p>
51+
52+
<table style="border: 1px solid black;">
53+
<tbody>
54+
<tr>
55+
<th style="border: 1px solid black;">子数组下标</th>
56+
<th style="border: 1px solid black;">子数组</th>
57+
<th style="border: 1px solid black;">和</th>
58+
<th style="border: 1px solid black;">替换后的子数组(令 nums[1] = 1)</th>
59+
<th style="border: 1px solid black;">新的和</th>
60+
</tr>
61+
<tr>
62+
<td style="border: 1px solid black;">nums[0...2]</td>
63+
<td style="border: 1px solid black;">[-1, -2, 3]</td>
64+
<td style="border: 1px solid black;">0</td>
65+
<td style="border: 1px solid black;">[-1, 1, 3]</td>
66+
<td style="border: 1px solid black;">3</td>
67+
</tr>
68+
<tr>
69+
<td style="border: 1px solid black;">nums[0...3]</td>
70+
<td style="border: 1px solid black;">[-1, -2, 3, -1]</td>
71+
<td style="border: 1px solid black;">-1</td>
72+
<td style="border: 1px solid black;">[-1, 1, 3, -1]</td>
73+
<td style="border: 1px solid black;">2</td>
74+
</tr>
75+
<tr>
76+
<td style="border: 1px solid black;">nums[1...3]</td>
77+
<td style="border: 1px solid black;">[-2, 3, -1]</td>
78+
<td style="border: 1px solid black;">0</td>
79+
<td style="border: 1px solid black;">[1, 3, -1]</td>
80+
<td style="border: 1px solid black;">3</td>
81+
</tr>
82+
</tbody>
83+
</table>
84+
85+
<p>因此,<code>nums</code>&nbsp;在一次操作后是正的。</p>
86+
</div>
87+
88+
<p><strong class="example">示例 3:</strong></p>
89+
90+
<div class="example-block">
91+
<p><span class="example-io"><b>输入:</b>nums = [1,2,3]</span></p>
92+
93+
<p><span class="example-io"><b>输出:</b>0</span></p>
94+
95+
<p><strong>解释:</strong></p>
96+
97+
<p>数组已经是正的,所以不需要操作。</p>
98+
</div>
99+
100+
<p>&nbsp;</p>
101+
102+
<p><strong>提示:</strong></p>
103+
104+
<ul>
105+
<li><code>3 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
106+
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
107+
</ul>
108+
109+
<!-- description:end -->
110+
111+
## 解法
112+
113+
<!-- solution:start -->
114+
115+
### 方法一
116+
117+
<!-- tabs:start -->
118+
119+
#### Python3
120+
121+
```python
122+
123+
```
124+
125+
#### Java
126+
127+
```java
128+
129+
```
130+
131+
#### C++
132+
133+
```cpp
134+
135+
```
136+
137+
#### Go
138+
139+
```go
140+
141+
```
142+
143+
<!-- tabs:end -->
144+
145+
<!-- solution:end -->
146+
147+
<!-- problem:end -->

0 commit comments

Comments
 (0)