题解 | #只出现一次的数字#

只出现一次的数字

https://www.nowcoder.com/practice/c04bd25f0396471b90dfc30d96b9109b

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        // write code here
        int n = nums.size();
        int ans = 0;
        for(int i = 0; i < n; i++){
            ans ^= nums[i];
        }
        return ans;
    }
};

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务