Skip to content

Commit 7bbe144

Browse files
authored
feat: add weekly contest 424 (doocs#3768)
1 parent e646ee6 commit 7bbe144

File tree

14 files changed

+1053
-3
lines changed

14 files changed

+1053
-3
lines changed

solution/0200-0299/0263.Ugly Number/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tags:
1616

1717
<!-- description:start -->
1818

19-
<p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
19+
<p>An <strong>ugly number</strong> is a <em>positive</em> integer which does not have a prime factor other than 2, 3, and 5.</p>
2020

2121
<p>Given an integer <code>n</code>, return <code>true</code> <em>if</em> <code>n</code> <em>is an <strong>ugly number</strong></em>.</p>
2222

@@ -34,7 +34,7 @@ tags:
3434
<pre>
3535
<strong>Input:</strong> n = 1
3636
<strong>Output:</strong> true
37-
<strong>Explanation:</strong> 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.
37+
<strong>Explanation:</strong> 1 has no prime factors.
3838
</pre>
3939

4040
<p><strong class="example">Example 3:</strong></p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3354.Make%20Array%20Elements%20Equal%20to%20Zero/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3354. 使数组元素等于零](https://leetcode.cn/problems/make-array-elements-equal-to-zero)
10+
11+
[English Version](/solution/3300-3399/3354.Make%20Array%20Elements%20Equal%20to%20Zero/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个整数数组&nbsp;<code>nums</code> 。</p>
18+
19+
<p>开始时,选择一个满足 <code>nums[curr] == 0</code> 的起始位置&nbsp;<code>curr</code>&nbsp;,并选择一个移动 <strong>方向</strong>&nbsp;:向左或者向右。</p>
20+
21+
<p>此后,你需要重复下面的过程:</p>
22+
23+
<ul>
24+
<li>如果&nbsp;<code>curr</code>&nbsp;超过范围&nbsp;<code>[0, n - 1]</code> ,过程结束。</li>
25+
<li>如果&nbsp;<code>nums[curr] == 0</code> ,沿当前方向继续移动:如果向右移,则 <strong>递增</strong>&nbsp;<code>curr</code>&nbsp;;如果向左移,则 <strong>递减</strong>&nbsp;<code>curr</code>&nbsp;。</li>
26+
<li>如果&nbsp;<code>nums[curr] &gt; 0</code>:
27+
<ul>
28+
<li>将&nbsp;<code>nums[curr]</code>&nbsp;减&nbsp;1 。</li>
29+
<li><strong>反转</strong>&nbsp;移动方向(向左变向右,反之亦然)。</li>
30+
<li>沿新方向移动一步。</li>
31+
</ul>
32+
</li>
33+
</ul>
34+
35+
<p>如果在结束整个过程后,<code>nums</code>&nbsp;中的所有元素都变为 0 ,则认为选出的初始位置和移动方向 <strong>有效</strong>&nbsp;。</p>
36+
37+
<p>返回可能的有效选择方案数目。</p>
38+
39+
<p>&nbsp;</p>
40+
41+
<p><b>示例 1:</b></p>
42+
43+
<div class="example-block">
44+
<p><span class="example-io"><b>输入:</b>nums = [1,0,2,0,3]</span></p>
45+
46+
<p><span class="example-io"><b>输出:</b>2</span></p>
47+
48+
<p><b>解释:</b></p>
49+
50+
<p>可能的有效选择方案如下:</p>
51+
52+
<ul>
53+
<li>选择&nbsp;<code>curr = 3</code>&nbsp;并向左移动。
54+
55+
<ul>
56+
<li><code>[1,0,2,<strong><u>0</u></strong>,3] -&gt; [1,0,<strong><u>2</u></strong>,0,3] -&gt; [1,0,1,<strong><u>0</u></strong>,3] -&gt; [1,0,1,0,<strong><u>3</u></strong>] -&gt; [1,0,1,<strong><u>0</u></strong>,2] -&gt; [1,0,<strong><u>1</u></strong>,0,2] -&gt; [1,0,0,<strong><u>0</u></strong>,2] -&gt; [1,0,0,0,<strong><u>2</u></strong>] -&gt; [1,0,0,<strong><u>0</u></strong>,1] -&gt; [1,0,<strong><u>0</u></strong>,0,1] -&gt; [1,<strong><u>0</u></strong>,0,0,1] -&gt; [<strong><u>1</u></strong>,0,0,0,1] -&gt; [0,<strong><u>0</u></strong>,0,0,1] -&gt; [0,0,<strong><u>0</u></strong>,0,1] -&gt; [0,0,0,<strong><u>0</u></strong>,1] -&gt; [0,0,0,0,<strong><u>1</u></strong>] -&gt; [0,0,0,0,0]</code>.</li>
57+
</ul>
58+
</li>
59+
<li>选择&nbsp;<code>curr = 3</code>&nbsp;并向右移动。
60+
<ul>
61+
<li><code>[1,0,2,<strong><u>0</u></strong>,3] -&gt; [1,0,2,0,<strong><u>3</u></strong>] -&gt; [1,0,2,<strong><u>0</u></strong>,2] -&gt; [1,0,<strong><u>2</u></strong>,0,2] -&gt; [1,0,1,<strong><u>0</u></strong>,2] -&gt; [1,0,1,0,<strong><u>2</u></strong>] -&gt; [1,0,1,<strong><u>0</u></strong>,1] -&gt; [1,0,<strong><u>1</u></strong>,0,1] -&gt; [1,0,0,<strong><u>0</u></strong>,1] -&gt; [1,0,0,0,<strong><u>1</u></strong>] -&gt; [1,0,0,<strong><u>0</u></strong>,0] -&gt; [1,0,<strong><u>0</u></strong>,0,0] -&gt; [1,<strong><u>0</u></strong>,0,0,0] -&gt; [<strong><u>1</u></strong>,0,0,0,0] -&gt; [0,0,0,0,0].</code></li>
62+
</ul>
63+
</li>
64+
65+
</ul>
66+
</div>
67+
68+
<p><b>示例 2:</b></p>
69+
70+
<div class="example-block">
71+
<p><span class="example-io"><b>输入:</b>nums = [2,3,4,0,4,1,0]</span></p>
72+
73+
<p><span class="example-io"><b>输出:</b>0</span></p>
74+
75+
<p><b>解释:</b></p>
76+
77+
<p>不存在有效的选择方案。</p>
78+
</div>
79+
80+
<p>&nbsp;</p>
81+
82+
<p><b>提示:</b></p>
83+
84+
<ul>
85+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
86+
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
87+
<li>至少存在一个元素&nbsp;<code>i</code>&nbsp;满足&nbsp;<code>nums[i] == 0</code> 。</li>
88+
</ul>
89+
90+
<!-- description:end -->
91+
92+
## 解法
93+
94+
<!-- solution:start -->
95+
96+
### 方法一
97+
98+
<!-- tabs:start -->
99+
100+
#### Python3
101+
102+
```python
103+
104+
```
105+
106+
#### Java
107+
108+
```java
109+
110+
```
111+
112+
#### C++
113+
114+
```cpp
115+
116+
```
117+
118+
#### Go
119+
120+
```go
121+
122+
```
123+
124+
<!-- tabs:end -->
125+
126+
<!-- solution:end -->
127+
128+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3354.Make%20Array%20Elements%20Equal%20to%20Zero/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3354. Make Array Elements Equal to Zero](https://leetcode.com/problems/make-array-elements-equal-to-zero)
10+
11+
[中文文档](/solution/3300-3399/3354.Make%20Array%20Elements%20Equal%20to%20Zero/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given an integer array <code>nums</code>.</p>
18+
19+
<p>Start by selecting a starting position <code>curr</code> such that <code>nums[curr] == 0</code>, and choose a movement <strong>direction</strong> of&nbsp;either left or right.</p>
20+
21+
<p>After that, you repeat the following process:</p>
22+
23+
<ul>
24+
<li>If <code>curr</code> is out of the range <code>[0, n - 1]</code>, this process ends.</li>
25+
<li>If <code>nums[curr] == 0</code>, move in the current direction by <strong>incrementing</strong> <code>curr</code> if you are moving right, or <strong>decrementing</strong> <code>curr</code> if you are moving left.</li>
26+
<li>Else if <code>nums[curr] &gt; 0</code>:
27+
<ul>
28+
<li>Decrement <code>nums[curr]</code> by 1.</li>
29+
<li><strong>Reverse</strong>&nbsp;your movement direction (left becomes right and vice versa).</li>
30+
<li>Take a step in your new direction.</li>
31+
</ul>
32+
</li>
33+
</ul>
34+
35+
<p>A selection of the initial position <code>curr</code> and movement direction is considered <strong>valid</strong> if every element in <code>nums</code> becomes 0 by the end of the process.</p>
36+
37+
<p>Return the number of possible <strong>valid</strong> selections.</p>
38+
39+
<p>&nbsp;</p>
40+
<p><strong class="example">Example 1:</strong></p>
41+
42+
<div class="example-block">
43+
<p><strong>Input:</strong> <span class="example-io">nums = [1,0,2,0,3]</span></p>
44+
45+
<p><strong>Output:</strong> <span class="example-io">2</span></p>
46+
47+
<p><strong>Explanation:</strong></p>
48+
49+
<p>The only possible valid selections are the following:</p>
50+
51+
<ul>
52+
<li>Choose <code>curr = 3</code>, and a movement direction to the left.
53+
54+
<ul>
55+
<li><code>[1,0,2,<strong><u>0</u></strong>,3] -&gt; [1,0,<strong><u>2</u></strong>,0,3] -&gt; [1,0,1,<strong><u>0</u></strong>,3] -&gt; [1,0,1,0,<strong><u>3</u></strong>] -&gt; [1,0,1,<strong><u>0</u></strong>,2] -&gt; [1,0,<strong><u>1</u></strong>,0,2] -&gt; [1,0,0,<strong><u>0</u></strong>,2] -&gt; [1,0,0,0,<strong><u>2</u></strong>] -&gt; [1,0,0,<strong><u>0</u></strong>,1] -&gt; [1,0,<strong><u>0</u></strong>,0,1] -&gt; [1,<strong><u>0</u></strong>,0,0,1] -&gt; [<strong><u>1</u></strong>,0,0,0,1] -&gt; [0,<strong><u>0</u></strong>,0,0,1] -&gt; [0,0,<strong><u>0</u></strong>,0,1] -&gt; [0,0,0,<strong><u>0</u></strong>,1] -&gt; [0,0,0,0,<strong><u>1</u></strong>] -&gt; [0,0,0,0,0]</code>.</li>
56+
</ul>
57+
</li>
58+
<li>Choose <code>curr = 3</code>, and a movement direction to the right.
59+
<ul>
60+
<li><code>[1,0,2,<strong><u>0</u></strong>,3] -&gt; [1,0,2,0,<strong><u>3</u></strong>] -&gt; [1,0,2,<strong><u>0</u></strong>,2] -&gt; [1,0,<strong><u>2</u></strong>,0,2] -&gt; [1,0,1,<strong><u>0</u></strong>,2] -&gt; [1,0,1,0,<strong><u>2</u></strong>] -&gt; [1,0,1,<strong><u>0</u></strong>,1] -&gt; [1,0,<strong><u>1</u></strong>,0,1] -&gt; [1,0,0,<strong><u>0</u></strong>,1] -&gt; [1,0,0,0,<strong><u>1</u></strong>] -&gt; [1,0,0,<strong><u>0</u></strong>,0] -&gt; [1,0,<strong><u>0</u></strong>,0,0] -&gt; [1,<strong><u>0</u></strong>,0,0,0] -&gt; [<strong><u>1</u></strong>,0,0,0,0] -&gt; [0,0,0,0,0].</code></li>
61+
</ul>
62+
</li>
63+
64+
</ul>
65+
</div>
66+
67+
<p><strong class="example">Example 2:</strong></p>
68+
69+
<div class="example-block">
70+
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,4,0,4,1,0]</span></p>
71+
72+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
73+
74+
<p><strong>Explanation:</strong></p>
75+
76+
<p>There are no possible valid selections.</p>
77+
</div>
78+
79+
<p>&nbsp;</p>
80+
<p><strong>Constraints:</strong></p>
81+
82+
<ul>
83+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
84+
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
85+
<li>There is at least one element <code>i</code> where <code>nums[i] == 0</code>.</li>
86+
</ul>
87+
88+
<!-- description:end -->
89+
90+
## Solutions
91+
92+
<!-- solution:start -->
93+
94+
### Solution 1
95+
96+
<!-- tabs:start -->
97+
98+
#### Python3
99+
100+
```python
101+
102+
```
103+
104+
#### Java
105+
106+
```java
107+
108+
```
109+
110+
#### C++
111+
112+
```cpp
113+
114+
```
115+
116+
#### Go
117+
118+
```go
119+
120+
```
121+
122+
<!-- tabs:end -->
123+
124+
<!-- solution:end -->
125+
126+
<!-- problem:end -->

0 commit comments

Comments
 (0)