Skip to content

Practice Number Complement

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#476
LeetCode Problem

Number Complement

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 num, return its complement. Example 1: Example 2: Constraints: Note: This question is the same as 1009: https://leetcode.com/problems/complement-of-base-10-integer/

Source: Number Complement on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
num = 5
Output
2

# Example 2

Input
num = 1
Output
0

Constraints

1 <= num < 2^31

Related LeetCode Problems

Practice more problems similar to Number Complement.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.