We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Simply having "Bit Manipulation" in the title was a good hint. My first thought was to keep a count of each number seen in a hashtable, then loop through the hashtable and print the item that only had 1 for a count. That's O(n) for time complexity, but O(n) for storage. The bitwise solution goes down to O(1) for storage.
Bit Manipulation: Lonely Integer
You are viewing a single comment's thread. Return to all comments →
Simply having "Bit Manipulation" in the title was a good hint. My first thought was to keep a count of each number seen in a hashtable, then loop through the hashtable and print the item that only had 1 for a count. That's O(n) for time complexity, but O(n) for storage. The bitwise solution goes down to O(1) for storage.
Here's my solution in Python 2: