zoukankan      html  css  js  c++  java
  • 136. 只出现一次的数字

    题目

    代码

    class Solution {
    public:
        int singleNumber(vector<int>& nums) {
            int temp=0;
            for(auto i:nums)
            {
                temp^=i;
            }
            return temp;
            //每个数字和自己异或的结果为0,所以唯一的一个数字会被留下来
        }
    };

    思路

    只需要知道一个原理,异或(两个数字不同则为1)

    因此,如果两个重复的数字 1101 与1101异或则会为0。

    https://github.com/li-zheng-hao
  • 相关阅读:
    三范式
    作用域
    函数传参
    js数据类型
    纯css小图标
    js生成div
    js模拟微信聊天窗口
    js图片切换
    js this指向
    常用实体字符
  • 原文地址:https://www.cnblogs.com/lizhenghao126/p/11053652.html
Copyright © 2011-2022 走看看