Number Complement LeetCode Solution - The Coding Shala
Home >> LeetCode >> Number Complement
In this post, we will learn how to solve LeetCode's Number Complement Problem and will implement its solution in Java.
Number Complement Problem
Given a positive integer num, output its complement number. The complement strategy is to flip the bits of its binary representation.
Input: num = 5
Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
Practice this problem on LeetCode.
LeetCode - Number Complement Java Solution
Just flip the bit and make decimal value from it.
Using bit Manipulation.
Other Posts You May Like
- LeetCode - Letter Case Permutation
- LeetCode - XOR operation in an Array
- LeetCode - Find the Difference
- LeetCode - Number of steps to Reduce number to zero
- LeetCode - Binary Number with Alternating Bits