1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# @Title: 数组中数字出现的次数 II (数组中数字出现的次数 II LCOF)
# @Author: 15816537946@163.com
# @Date: 2022-02-22 00:38:00
# @Runtime: 480 ms
# @Memory: 16 MB
class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        counts = [0] * 32
        for num in nums:
            for j in range(32):
                counts[j] += num & 1
                num >>= 1
        res, m = 0, 3
        for i in range(32):
            res <<= 1
            res |= counts[31 - i] % m
        return res if counts[31] % m == 0 else ~(res ^ 0xffffffff)