java.lang.Object
g2501_2600.s2595_number_of_even_and_odd_bits.Solution

public class Solution extends Object
2595 - Number of Even and Odd Bits.<p>Easy</p> <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><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 17</p> <p><strong>Output:</strong> [2,0]</p> <p><strong>Explanation:</strong></p> <p>The binary representation of 17 is 10001.</p> <p>It contains 1 on the 0<sup>th</sup> and 4<sup>th</sup> indices.</p> <p>There are 2 even and 0 odd indices.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 2</p> <p><strong>Output:</strong> [0,1]</p> <p><strong>Explanation:</strong></p> <p>The binary representation of 2 is 10.</p> <p>It contains 1 on the 1<sup>st</sup> index.</p> <p>There are 0 even and 1 odd indices.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • evenOddBit

      public int[] evenOddBit(int n)