[再エンコード]シングル番号


https://leetcode.com/problems/single-number/
1.完全なコード
1.xORプール
class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        result = 0
        for num in nums:
            result = result ^ num
        return result
2.資料型解答
class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        d = defaultdict(int)
        for num in nums:
            d[num] += 1
        for i in d:
            if d[i] == 1:
                return i
2.後期
first = 0
a = first ^ 70  #출력 70
b = a ^ 34      #출력 100
c = b ^ 70      #출력 34
d = c ^ 20      #출력 54
e = d ^ 34      #출력 20
2回のXOR演算を使用した70と34は初期化されていますが、1回のXOR演算を使用した20だけが値を保持します.重要なのは、同じ数が現れる順番は関係ありません.
例えば、13^512^7^512^9^7^13のような複雑な演算も簡単に答えを得ることができる.
2回使用した135127は消滅し、9万のみが残った.