Given 2*n + 1 numbers, every numbers occurs twice except one, find it.

 
Example

Given [1,2,2,1,3,4,3], return 4

Challenge

One-pass, constant extra space.

题意

给出2*n + 1 个的数字,除其中一个数字之外其他每个数字均出现两次,找到这个数字。

解法一:

 class Solution {
public:
/*
* @param A: An integer array
* @return: An integer
*/
int singleNumber(vector<int> &A) {
int num = A[];
for (int i = ; i < A.size(); ++i) {
num ^= A[i];
} return num;
}
};

利用异或的性质,相同为0

82. Single Number【easy】的更多相关文章

  1. 136. Single Number【LeetCode】异或运算符,算法,java

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

  2. 491. Palindrome Number【easy】

    Check a positive number is a palindrome or not. A palindrome number is that if you reverse the whole ...

  3. 170. Two Sum III - Data structure design【easy】

    170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...

  4. 203. Remove Linked List Elements【easy】

    203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...

  5. 88. Merge Sorted Array【easy】

    88. Merge Sorted Array[easy] Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 ...

  6. 605. Can Place Flowers【easy】

    605. Can Place Flowers[easy] Suppose you have a long flowerbed in which some of the plots are plante ...

  7. 485. Max Consecutive Ones【easy】

    485. Max Consecutive Ones[easy] Given a binary array, find the maximum number of consecutive 1s in t ...

  8. 167. Two Sum II - Input array is sorted【easy】

    167. Two Sum II - Input array is sorted[easy] Given an array of integers that is already sorted in a ...

  9. 283. Move Zeroes【easy】

    283. Move Zeroes[easy] Given an array nums, write a function to move all 0's to the end of it while ...

随机推荐

  1. Forms.Timer、Timers.Timer、Threading.Timer的研究

    .NET Framework里面提供了三种Timer System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer 一.S ...

  2. SVN — subclipse操作指引

    摘自: http://jiangzhengjun.iteye.com/blog/491824 安装插件:请参照http://subclipse.tigris.org/servlets/ProjectP ...

  3. struts2-core-2.0.14更新到2.3.15

    struts2-core-2.0.14更新到2.3.15 将低版本的struts2-core更新到最新版本2.3.15,更新jar包,有这个几个 1. struts2-core-2.0.14.jar ...

  4. [IDEA]IntelliJ IDEA 报 This license BIG3CLIK6F has been cancelled 错误

    JetBrains 最近封杀了lanyus提供的序列号,用的人多了,自然会引起JetBrains的注意. 在激活时,会先在本地做一次验证,然后会把注册码发送到JetBrains的账号服务器上accou ...

  5. Linux shell 提取文件名和目录名

    ${}用于字符串的读取,提取和替换功能,可以使用${} 提取字符串 1.提取文件名 [root@localhost log]# var=/dir1/dir2/file.txt [root@localh ...

  6. <The Art of Readable Code> 笔记二 (上)

    第2章  封装信息到名字 (Packing information into names) 2.1  use specific words GetPage() 不如 FetchPage() 和 Dow ...

  7. android开发之MediaPlayer+Service MP3播放器

    import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.Lis ...

  8. weblogic 内存 及 内存溢出

    . 区分JVM虚拟机选项:Xms Xmx PermSize MaxPermSize JVM限制:相关操作系统的数据模型(32-bt还是64-bit)限制:系统的可用虚拟内存限制:系统的可用物理内存限制 ...

  9. iOS arc和非arc 适用 宏

    iOS arc和非arc 适用 宏 1:使用宏 + (void)showAlertWithMessage:(NSString *)messages { dispatch_async(dispatch_ ...

  10. VMware Workstation的网络连接方式:NAT、桥接和Host Only

    安装完VMware Workstation后会自动生成两个网络连接:VMware Network Adapter VMnet8 和 VMware Network Adapter VMnet1(通常称为 ...