Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
給一個整數的非空陣列,每個元素出現三次,只有一個出現一次,請找到這個孤單的傢伙。
注意:你的演算法應該是線性複雜度(O(N)),你可以完成並不使用額外的空間嗎?
map
做hash table
,存好之後找只出現一次的元素。LeetCode
C++