python - single number - 88ms

  • 0
    class Solution(object):
        def singleNumber(self, nums):
            :type nums: List[int]
            :rtype: int
            ans = 0
            for i in range(32)[::-1]:
                prefix = [(n>>i)&0x1 for n in nums]
                ans |= (sum(prefix)%3)<<i
            return ans if ans < pow(2,31) else ans - pow(2,32)

    I believe all solutions here that use a counter or sum are undermining the spirit of the question.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.