1. 程式人生 > 其它 >LeetCode:136. 只出現一次的數字

LeetCode:136. 只出現一次的數字

技術標籤:力扣刷題

136. 只出現一次的數字

思路:異或處理如果兩個一樣的異或完為其本身,若不相同則為其本身。
技巧:accumulate(nums.begin(),nums.end(),0,bit_xor());裡面accumulate為累加函式,bit_xor()為異或操作。
class Solution {
public:
    int singleNumber(vector<int>& nums) {
       return accumulate(nums.begin(),nums.end(),0,bit_xor());
    }
};