Skip to content

Commit 6f41312

Browse files
committed
Create README - LeetHub
1 parent 902d4e8 commit 6f41312

File tree

1 file changed

+46
-0
lines changed
  • 3493-maximum-number-of-operations-to-move-ones-to-the-end

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<h2><a href="https://leetcode.com/problems/maximum-number-of-operations-to-move-ones-to-the-end">3493. Maximum Number of Operations to Move Ones to the End</a></h2><h3>Medium</h3><hr><p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p>
2+
3+
<p>You can perform the following operation on the string <strong>any</strong> number of times:</p>
4+
5+
<ul>
6+
<li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that <code>s[i] == &#39;1&#39;</code> and <code>s[i + 1] == &#39;0&#39;</code>.</li>
7+
<li>Move the character <code>s[i]</code> to the <strong>right</strong> until it reaches the end of the string or another <code>&#39;1&#39;</code>. For example, for <code>s = &quot;010010&quot;</code>, if we choose <code>i = 1</code>, the resulting string will be <code>s = &quot;0<strong><u>001</u></strong>10&quot;</code>.</li>
8+
</ul>
9+
10+
<p>Return the <strong>maximum</strong> number of operations that you can perform.</p>
11+
12+
<p>&nbsp;</p>
13+
<p><strong class="example">Example 1:</strong></p>
14+
15+
<div class="example-block">
16+
<p><strong>Input:</strong> <span class="example-io">s = &quot;1001101&quot;</span></p>
17+
18+
<p><strong>Output:</strong> <span class="example-io">4</span></p>
19+
20+
<p><strong>Explanation:</strong></p>
21+
22+
<p>We can perform the following operations:</p>
23+
24+
<ul>
25+
<li>Choose index <code>i = 0</code>. The resulting string is <code>s = &quot;<u><strong>001</strong></u>1101&quot;</code>.</li>
26+
<li>Choose index <code>i = 4</code>. The resulting string is <code>s = &quot;0011<u><strong>01</strong></u>1&quot;</code>.</li>
27+
<li>Choose index <code>i = 3</code>. The resulting string is <code>s = &quot;001<strong><u>01</u></strong>11&quot;</code>.</li>
28+
<li>Choose index <code>i = 2</code>. The resulting string is <code>s = &quot;00<strong><u>01</u></strong>111&quot;</code>.</li>
29+
</ul>
30+
</div>
31+
32+
<p><strong class="example">Example 2:</strong></p>
33+
34+
<div class="example-block">
35+
<p><strong>Input:</strong> <span class="example-io">s = &quot;00111&quot;</span></p>
36+
37+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
38+
</div>
39+
40+
<p>&nbsp;</p>
41+
<p><strong>Constraints:</strong></p>
42+
43+
<ul>
44+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
45+
<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
46+
</ul>

0 commit comments

Comments
 (0)