mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-11 18:31:41 +08:00
批量更新数据
This commit is contained in:
@@ -1,35 +1,45 @@
|
||||
<p>You are given a <strong>positive</strong> integer <code>n</code>.</p>
|
||||
|
||||
<p>Let <code>even</code> denote the number of even indices in the binary representation of <code>n</code> (<strong>0-indexed</strong>) with value <code>1</code>.</p>
|
||||
|
||||
<p>Let <code>odd</code> denote the number of odd indices in the binary representation of <code>n</code> (<strong>0-indexed</strong>) with value <code>1</code>.</p>
|
||||
|
||||
<p>Return <em>an integer array </em><code>answer</code><em> where </em><code>answer = [even, odd]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 17
|
||||
<strong>Output:</strong> [2,0]
|
||||
<strong>Explanation:</strong> The binary representation of 17 is 10001.
|
||||
It contains 1 on the 0<sup>th</sup> and 4<sup>th</sup> indices.
|
||||
There are 2 even and 0 odd indices.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2
|
||||
<strong>Output:</strong> [0,1]
|
||||
<strong>Explanation:</strong> The binary representation of 2 is 10.
|
||||
It contains 1 on the 1<sup>st</sup> index.
|
||||
There are 0 even and 1 odd indices.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 1000</code></li>
|
||||
</ul>
|
||||
<p>You are given a <strong>positive</strong> integer <code>n</code>.</p>
|
||||
|
||||
<p>Let <code>even</code> denote the number of even indices in the binary representation of <code>n</code> with value 1.</p>
|
||||
|
||||
<p>Let <code>odd</code> denote the number of odd indices in the binary representation of <code>n</code> with value 1.</p>
|
||||
|
||||
<p>Note that bits are indexed from <strong>right to left</strong> in the binary representation of a number.</p>
|
||||
|
||||
<p>Return the array <code>[even, odd]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 50</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[1,2]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The binary representation of 50 is <code>110010</code>.</p>
|
||||
|
||||
<p>It contains 1 on indices 1, 4, and 5.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[0,1]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The binary representation of 2 is <code>10</code>.</p>
|
||||
|
||||
<p>It contains 1 only on index 1.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 1000</code></li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user