LeetCode 260 : Single Number III |

Опубликовано: 25 Июнь 2026
на канале: CodeCraft Nitish
2
1

Problem: Single Number III (LeetCode #260)

Approach:
In this solution, we use an unordered_map (HashMap) approach to find the two elements that appear exactly once in the array.

The idea is:
Traverse the array and count the frequency of each element
Store frequencies using unordered_map
Elements appearing twice will have frequency 2
Elements appearing once will have frequency 1
Traverse the map and collect all elements with frequency 1

Steps:

1. Create an unordered_map to store frequencies
2. Traverse the array and count occurrences of each element
3. Create a result vector
4. Traverse the frequency map
5. Check if frequency is equal to 1
6. Add the element to the result vector
7. Return the result

Time Complexity:
O(n)

Space Complexity:
O(n)

GitHub:
https://github.com/Nitishkumar0517768

LeetCode Profile:
https://leetcode.com/u/Nitishkumar_05/

LinkedIn:
  / nitish-kumar-03a34a3a1  

Notes:
Beginner-friendly HashMap approach
Easy to understand and implement
Uses frequency counting to identify unique elements
The optimal solution uses bit manipulation with O(1) extra space, but this approach is simpler for learning

#leetcode #cpp #coding #dsa #programming #codecraft #datastructures #datastructureandalgorithm