Now this is much more complex. No simple operation to solve.
The solution is actually using binary to simulate ternary.
Solution:
# T:O(n) S:O(1) lass Solution: # @param A, a list of integer # @return an integer def singleNumber(self, A): one, two = 0, 0 for x in A: one, two = (~x & one) | (x & ~one & ~two), (~x & two) | (x & one) return oneRun Time: 64 ms
No comments:
Post a Comment