leetcode-----136. 只出现一次的数字

代码

/*
 * @lc app=leetcode.cn id=136 lang=cpp
 *
 * [136] 只出现一次的数字
 * x ^ x = 0
 */

// @lc code=start
class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int ans = 0;
        for (auto x: nums) ans ^= x;
        return ans;
    }
};
// @lc code=end
posted @ 2020-08-01 17:10  景云ⁿ  阅读(74)  评论(0编辑  收藏  举报