problem_solving_11.py 395 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
"""
只出现一次的数字
"""
from typing import List


class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        """
        异或运算
        :param nums:
        :return:
        """
        result = 0
        for i in nums:
            result ^= i
        return result


if __name__ == '__main__':
    root = Solution().singleNumber([2, 2, 1, 1, 3])
    print(root)