1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (English)/奇偶位数(English) [number-of-even-and-odd-bits].html

46 lines
1.3 KiB
HTML

<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>&nbsp;</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>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 1000</code></li>
</ul>