2595. Number of Even and Odd Bits Easy

@problem@discussion
#Bit Manipulation



1/**
2 * [2595] Number of Even and Odd Bits
3 *
4 * You are given a positive integer n.
5 * Let even denote the number of even indices in the binary representation of n with value 1.
6 * Let odd denote the number of odd indices in the binary representation of n with value 1.
7 * Note that bits are indexed from right to left in the binary representation of a number.
8 * Return the array [even, odd].
9 *  
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">n = 50</span>
13 * Output: <span class="example-io">[1,2]</span>
14 * Explanation:
15 * The binary representation of 50 is 110010.
16 * It contains 1 on indices 1, 4, and 5.
17 * </div>
18 * <strong class="example">Example 2:
19 * <div class="example-block">
20 * Input: <span class="example-io">n = 2</span>
21 * Output: <span class="example-io">[0,1]</span>
22 * Explanation:
23 * The binary representation of 2 is 10.
24 * It contains 1 only on index 1.
25 * </div>
26 *  
27 * Constraints:
28 * 
29 * 	1 <= n <= 1000
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/number-of-even-and-odd-bits/
35// discuss: https://leetcode.com/problems/number-of-even-and-odd-bits/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn even_odd_bit(n: i32) -> Vec<i32> {
41        vec![]
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_2595() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.