1009. Complement of Base 10 Integer Easy

@problem@discussion
#Bit Manipulation



1/**
2 * [1009] Complement of Base 10 Integer
3 *
4 * The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.
5 * 
6 * 	For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2.
7 * 
8 * Given an integer n, return its complement.
9 *  
10 * Example 1:
11 * 
12 * Input: n = 5
13 * Output: 2
14 * Explanation: 5 is "101" in binary, with complement "010" in binary, which is 2 in base-10.
15 * 
16 * Example 2:
17 * 
18 * Input: n = 7
19 * Output: 0
20 * Explanation: 7 is "111" in binary, with complement "000" in binary, which is 0 in base-10.
21 * 
22 * Example 3:
23 * 
24 * Input: n = 10
25 * Output: 5
26 * Explanation: 10 is "1010" in binary, with complement "0101" in binary, which is 5 in base-10.
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	0 <= n < 10^9
32 * 
33 *  
34 * Note: This question is the same as 476: <a href="https://leetcode.com/problems/number-complement/" target="_blank">https://leetcode.com/problems/number-complement/</a>
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/complement-of-base-10-integer/
40// discuss: https://leetcode.com/problems/complement-of-base-10-integer/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn bitwise_complement(n: i32) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_1009() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.