LeetCode 136: Single number 🔂 Approach 1: Hash Map - We use a dictionary to count occurrences of each number. - Go through the list and update counts. - Finally, look for the number with a count of 1—that’s our answer! Complexity: - Time Complexity: O(n) — Check all items. - Space Complexity: O(n) — Dictionary to track counts. Approach 2: XOR (Bit Manipulation) - Initialize a variable ans = 0. - XOR every number in the list with ans. - Pairs cancel out (because a ^ a = 0 and 0 ^ b = b), so only the single number remains at the end. Complexity: - Time Complexity: O(n) — Just one pass through all numbers. - Space Complexity: O(1) — No extras, just ans. The XOR trick is super efficient and works like magic due to properties of binary operations! Check out the problem here: https://lnkd.in/giUbz53v Keep going, keep revising, and keep building confidence! 💪🔥 #DSA #Coding #ProblemSolving #Learning

To view or add a comment, sign in

Explore content categories