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?

解题:

此题可直接运用异或运算的性质:N^A^A = N

代码:

 class Solution {
public:
int singleNumber(int A[], int n) {
for (int i = ; i < n; ++i)
A[] ^= A[i];
return A[];
}
};

但是在leetcode网站性能分析中,异或运算(19ms)不是最快的,不知道还有没有其他算法可以达到10ms以下。

【Leetcode】【Medium】Single Number的更多相关文章

  1. 【LeetCode题意分析&解答】40. Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  2. 【LeetCode题意分析&解答】37. Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  3. 【LeetCode题意分析&解答】35. Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  4. ACM金牌选手整理的【LeetCode刷题顺序】

    算法和数据结构知识点图 首先,了解算法和数据结构有哪些知识点,在后面的学习中有 大局观,对学习和刷题十分有帮助. 下面是我花了一天时间花的算法和数据结构的知识结构,大家可以看看. 后面是为大家 精心挑 ...

  5. 【leetcode刷题笔记】Single Number II

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

  6. 【leetcode刷题笔记】Single Number

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

  7. 【LeetCode算法题库】Day3:Reverse Integer & String to Integer (atoi) & Palindrome Number

    [Q7]  把数倒过来 Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Outpu ...

  8. 【LeetCode每天一题】Fibonacci Number(斐波那契数列)

    The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...

  9. 【leetcode刷题笔记】Number of 1 Bits

    Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...

  10. 【leetcode刷题笔记】Excel Sheet Column Number

    Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...

随机推荐

  1. 打开页面时就提交,可以做一些自动登陆 还有SICLOGIN的测试代码

      <HTML> <head> <title> Untitled Document</title > (1)自动提交表单: <meta http- ...

  2. 补档 VS远程调试

    先说概念 开发机:将编译好的程序部署到目标机器上执行.配置 VS 工程,建立与目标机的连接,开始远程调试. 目标机:负责执行目标程序.安装和运行远程工具 (Remote Debugger),等待来自开 ...

  3. kvm 虚拟网络命令操作

    2018-11-06 ```使用brctl命令创建网桥br1```# brctl addbr br1``` 删除网桥br1```# brctl delbr br1``` 将eth0端口加入网桥br1  ...

  4. ibatis配置文件中的XML解析错误The content of elements must consist of well-formed character data or markup.

    在检查过所有的标签名都没有问题的情况下. xml中的小于号属于非法字符. SQL语句中则可能需要小于号,此时就需要用<![CDATA[  ]]>将小于号包裹,如此不会被xml解析器解析. ...

  5. rancher初级(搭建+基本操作+web应用部署)

    Rancher搭建 首先rancher需要安装了docker的linux环境,我的系统版本为 在docker的基础上启动rancher服务器,Rancher 服务器是一个 Docker image,所 ...

  6. llinux 目录结构 及Linux文件分享

    llinux 基础命令 及个人Linux文件分享 一, root用户名 @ 分隔符 kingle 主机名 ~当前所在目录 # root权限 $ 没分配权限用户 二, 书写格式:空格 [命令参数] 空格 ...

  7. DB Intro - MongoDB Basic

    mongoDB basic from:http://www.tutorialspoint.com/mongodb prject:https://github.com/chenxing12/l4mong ...

  8. Java开发环境搭建——IntelliJ Idea开发环境

    IntelliJ Idea版本选择由于公司使用JDK7,所以我选择安装Version 2016.1.4(手动安装试验出来的,最新版的2016.1.4启动时提示需要安装JDK8)下载 前面说明有误,其实 ...

  9. Android开发:使用Fragment改造TabActivity

    TabActivity在API 13(Android 3.2)被标记为过期,需要使用Fragment来实现,Fragment是Android 3.0引入的一个概念,主要就是为了适应各种不同的屏幕大小( ...

  10. 给string添加新的函数

    var str = "abcdefg";String.prototype.constr = function(){ return this.split('').join('-'); ...