单次出现的元素

single-number

http://www.nowcoder.com/questionTerminal/0bc646909e474ac5b031ec6836a47768

哇哈哈,位运算大法好。。。

两个异或=开心^^

//
// Created by jt on 2020/8/8.
//
#include 
using namespace std;
class Solution {
public:
    /**
     *
     * @param A int整型一维数组
     * @param n int A数组长度
     * @return int整型
     */
    int singleNumber(int* A, int n) {
        // write code here
        int result = 0;
        for (int i = 0; i < n; ++i) {
            result ^= A[i];
        }
        return result;
    }
};
刷遍天下无敌手 文章被收录于专栏

秋招刷题历程

全部评论

相关推荐

牛客52811839...:实习要写出来业务和产出,你这写的像流水账没人看。项目经历也没有,换个极简简历试试
点赞 评论 收藏
分享
评论
12
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务