Practice Complement of Base 10 Integer
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
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. Given an integer n, return its complement. Example 1: Example 2: Example 3: Constraints: Note: This question is the same as 476: https://leetcode.com/problems/number-complement/
Source: Complement of Base 10 Integer on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
n = 5
Output
2
# Example 2
Input
n = 7
Output
0
# Example 3
Input
n = 10
Output
5
Constraints
0 <= n < 10^9
Related LeetCode Problems
Practice more problems similar to Complement of Base 10 Integer.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.