Given an array of integers, every element appears twice except for one. Find that single one.

Note:

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

//意思是一堆数中找出没成对的那个,用异或效率最高A^0=A   A^A=0 最后可求出SingleNumber

public class Solution {

public int singleNumber(int[] A) {

        int res=0;

        for(int i=0;i<A.length;i++){

            res^=A[i];

        }

        return res;

    }

}

SingleNumber的更多相关文章

  1. SingleNumber python实现

    Single Number Given an array of integers, every element appears twice except for one. Find that sing ...

  2. Leetcode 136 137 260 SingleNumber I II III

    Leetccode 136 SingleNumber I Given an array of integers, every element appears twice except for one. ...

  3. leetcode — single-number

    /** * Source : https://oj.leetcode.com/problems/single-number/ * * * Given an array of integers, eve ...

  4. Leetcode SingleNumber I & II & III 136/137/260

    SingleNumber I: 题目链接:https://leetcode-cn.com/problems/single-number/ 题意: 给定一个非空整数数组,除了某个元素只出现一次以外,其余 ...

  5. LeetCode——single-number系列

    LeetCode--single-number系列 Question 1 Given an array of integers, every element appears twice except ...

  6. 【算法编程】找出仅仅出现一次的数-singleNumber

    题目意思: 一个数值数组中,大部分的数值出现两次,仅仅有一个数值仅仅出现过一次,求编程求出该数字. 要求,时间复杂度为线性,空间复杂度为O(1). 解题思路: 1.先排序.后查找. 因为排序的最快时间 ...

  7. [LeetCode]singleNumber

    题目:singleNumber Given an array of integers, every element appears twice except for one. Find that si ...

  8. LeetCode 2: single-number II

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  9. LeetCode 1: single-number

    Given an array of integers, every element appears twice except for one. Find that single one. soluti ...

随机推荐

  1. 使用node.js 文档里的方法写一个web服务器

    刚刚看了node.js文档里的一个小例子,就是用 node.js 写一个web服务器的小例子 上代码 (*^▽^*) //helloworld.js// 使用node.js写一个服务器 const h ...

  2. MongoDB在Windows2003上安装配置及使用

    本文档适用于MongoDB2.0.1版本在windows2003上的安装.配置,以及使用. 或者根据需要下载最新的稳定版本. 安装:将下载之后的压缩包解压到任意目录即可,本文假设解压到[D:\mong ...

  3. css - 紧贴底部的页脚

    有的时候,由于页面长度不够,页面底部的页脚会很尴尬的跑上来,如图: 有的同学可能会想用position:fixed;bottom:0;来永远居底.但有些场景确实不适合. 这是我从YII2中找到的简单解 ...

  4. iOS 提示更新 业务逻辑

    1, 当程序启动,先去APPstore 检查有没有新版本.没有新版本就不提示,有新版本才提示. 2,只有当有提示了,再去判断是强制更新还是普通提示. 3,当后台给返回要强制更新时,就给出提示,并且没有 ...

  5. Atitit. 包厢记时系统 的说明,教程,维护,故障排查手册v2 pb25.doc

    Atitit. 包厢记时系统 的说明,教程,维护,故障排查手册v2 pb25.doc 1. 服务器方面的维护1 1.1. 默认情况下,已经在系统的启动目录下增加了 个启动项目1 1.2. 后台服务.保 ...

  6. nginx服务器部署

    nginx(“engine x”)是一个高性能的HTTP和反向代理服务器.   安装nginx Linux下  sudo apt-get install nginx windows下 下载 nginx ...

  7. 转载-android studio 各种问题

    android studio 各种问题 1.dexDebug ExecException finished with non-zero exit value 2 全bug日志如下: (Error:Ex ...

  8. DataUml Design 介绍9 - DataUML 1.3版本功能(查询分析器功能等)

    DataUML 1.3 (下载)主要更新内容如下: 1.增加查询分析器功能: 2.增加打开历史文件记录功能: 3.修改查询对象功能: 4.增加显示对象长度功能: 5.增加配置显示表字段功能: 6.增加 ...

  9. Math函数的"四舍五入",Floor,Ceiling,Round的一些注意事项!

    1.Math.Round:四舍六入五取偶 引用内容 Math.Round(0.0) //0Math.Round(0.1) //0Math.Round(0.2) //0Math.Round(0.3) / ...

  10. 设计模式中类的关系之实现(Realization)

    实现关系是用来描述接口和实现接口的类或者构建结构之间的关系,接口是操作的集合,而这些操作就用于规定类或者构建结构的一种服务. 在接口和类之间的实现关系中,类实现了接口,类中的操作实现了接口中所声明的操 ...