Single Number 2 LeetCode Solution - The Coding Shala
In this post, we will learn how to solve LeetCode's Single Number 2 problem and will implement its solution in Java.
Single Number 2 Problem
Single Number 2 Java Solution
We can use HashMap to store the count of numbers.
Using Bit Manipulation.
As we know every element appears three times except for one. If a number appears three times then if we do a vertical sum of their binary number 1 comes three times.
Let's take an example if 2 appears three times then:
like this, if every element occurs three times then in their vertical sum every bit divides by 3 and if one element appears only once then that vertical bit sum will not divide by 3 so we need to figure out that bit only in our answer.
- LeetCode - Single Number
- Find XOR from 1 to n Numbers
- LeetCode - Bulb Switcher
- LeetCode - Simple XML Validator
- LeetCode - Degree of an Array