Skip to content

Commit 151bed0

Browse files
committed
Create README - LeetHub
1 parent 6351e59 commit 151bed0

File tree

1 file changed

+69
-0
lines changed
  • 3616-make-array-elements-equal-to-zero

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<h2><a href="https://leetcode.com/problems/make-array-elements-equal-to-zero">3616. Make Array Elements Equal to Zero</a></h2><h3>Easy</h3><hr><p>You are given an integer array <code>nums</code>.</p>
2+
3+
<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>
4+
5+
<p>After that, you repeat the following process:</p>
6+
7+
<ul>
8+
<li>If <code>curr</code> is out of the range <code>[0, n - 1]</code>, this process ends.</li>
9+
<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>
10+
<li>Else if <code>nums[curr] &gt; 0</code>:
11+
<ul>
12+
<li>Decrement <code>nums[curr]</code> by 1.</li>
13+
<li><strong>Reverse</strong>&nbsp;your movement direction (left becomes right and vice versa).</li>
14+
<li>Take a step in your new direction.</li>
15+
</ul>
16+
</li>
17+
</ul>
18+
19+
<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>
20+
21+
<p>Return the number of possible <strong>valid</strong> selections.</p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong class="example">Example 1:</strong></p>
25+
26+
<div class="example-block">
27+
<p><strong>Input:</strong> <span class="example-io">nums = [1,0,2,0,3]</span></p>
28+
29+
<p><strong>Output:</strong> <span class="example-io">2</span></p>
30+
31+
<p><strong>Explanation:</strong></p>
32+
33+
<p>The only possible valid selections are the following:</p>
34+
35+
<ul>
36+
<li>Choose <code>curr = 3</code>, and a movement direction to the left.
37+
38+
<ul>
39+
<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>
40+
</ul>
41+
</li>
42+
<li>Choose <code>curr = 3</code>, and a movement direction to the right.
43+
<ul>
44+
<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>
45+
</ul>
46+
</li>
47+
</ul>
48+
</div>
49+
50+
<p><strong class="example">Example 2:</strong></p>
51+
52+
<div class="example-block">
53+
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,4,0,4,1,0]</span></p>
54+
55+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
56+
57+
<p><strong>Explanation:</strong></p>
58+
59+
<p>There are no possible valid selections.</p>
60+
</div>
61+
62+
<p>&nbsp;</p>
63+
<p><strong>Constraints:</strong></p>
64+
65+
<ul>
66+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
67+
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
68+
<li>There is at least one element <code>i</code> where <code>nums[i] == 0</code>.</li>
69+
</ul>

0 commit comments

Comments
 (0)