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

只出现一次的数字(二)

https://www.nowcoder.com/practice/85cb47fc0c6c483fab7e5cefab54d9e5

using System;
using System.Collections.Generic;


class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param nums int整型一维数组
     * @return int整型
     */
    public int singleNumber (List<int> nums) {
        // write code here
        if (nums == null || nums.Count == 0)
            return 0;
        if (nums.Count == 1)
            return nums[0];
        int nR = 0;
        for (int n = 31; n >= 0; n--) {
            int nSum = 0;
            for (int i = 0; i < nums.Count; i++)
                nSum += (nums[i] >> n & 1);
            nR = (nSum % 3) + 2 * nR;
        }
        return nR;
    }
}

全部评论

相关推荐

投递长鑫存储等公司7个岗位
点赞 评论 收藏
分享
06-20 21:22
已编辑
门头沟学院 Java
纯真的河老师在喝茶:答应了就跑啊,实习随便跑啊,别被pua了,md就是找个廉价劳动力,还平稳过度正式工,到时候跟你说没转正
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-01 11:47
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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