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?

求出数组中只出现了一次的数(其他的数都出现了2次)

异或求解。

public class Solution {
public int singleNumber(int[] nums) {
int len = nums.length;
int result = nums[0];
for( int i = 1;i<len;i++){ result = result^nums[i]; }
return result;
}
}

leetcode 136. Single Number ----- java的更多相关文章

  1. leetcode 136 Single Number, 260 Single Number III

    leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...

  2. LeetCode 136. Single Number(只出现一次的数字)

    LeetCode 136. Single Number(只出现一次的数字)

  3. LeetCode 136. Single Number C++ 结题报告

    136. Single Number -- Easy 解答 相同的数,XOR 等于 0,所以,将所有的数字 XOR 就可以得到只出现一次的数 class Solution { public: int ...

  4. [LeetCode] 136. Single Number 单独数

    Given a non-empty array of integers, every element appears twice except for one. Find that single on ...

  5. leetcode 136. Single Number 、 137. Single Number II 、 260. Single Number III(剑指offer40 数组中只出现一次的数字)

    136. Single Number 除了一个数字,其他数字都出现了两遍. 用亦或解决,亦或的特点:1.相同的数结果为0,不同的数结果为1 2.与自己亦或为0,与0亦或为原来的数 class Solu ...

  6. LeetCode 136 Single Number(仅仅出现一次的数字)

    翻译 给定一个整型数组,除了某个元素外其余元素均出现两次. 找出这个仅仅出现一次的元素. 备注: 你的算法应该是一个线性时间复杂度. 你能够不用额外空间来实现它吗? 原文 Given an array ...

  7. Java for LeetCode 136 Single Number

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

  8. Java [Leetcode 136]Single Number

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

  9. LeetCode 136. Single Number (落单的数)

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

随机推荐

  1. git初识

    下载网上的开发员的项目 git clone https://github.com/xxxxxx/test.git 下载好,进入刚下载的好的test项目目录,可以修改对应的代码,然后 git statu ...

  2. Android 禁用以及捕捉home键

    最近要做个小项目,其中有需要禁止home键的需求,一开始以为不可以,感觉得root一下才行,后来查了一下,发现还是不少朋友都实现了这个功能,现在也引用一下,供大家参考一下: 1. 在activity中 ...

  3. SharePoint 2013 Nintex Workflow 工作流帮助(七)

    博客地址 http://blog.csdn.net/foxdave 工作流动作 11. Check out item(Libraries and lists分组) 与上一个对应,用于签出条目.如果一个 ...

  4. objective-c strong导致内存泄漏简单案例

    例如: @interface Test:NSObject{ id __strong obj_; } -(void) setObject:(id __strong)obj; @end @implemen ...

  5. php练习题:投票

    通过连接数据库,对数据库的增删改来实现一个投票的进行与结果的显示: 方法一: 主页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...

  6. objectarx 卸载加载arx模块

    通常情况下,加载卸载arx模块是使用 APPLOAD命令 使用ObjectARX 代码操作,也非常简单,使用2个全局函数即可,参数为名字有扩展名 C++ int acedArxLoad( const ...

  7. PHP文件系统处理(二)

    1.文件的打开和关闭(读文件中的内容,向文件中写内容)            读取文件中的内容                file_get_contents()     //php5以上 < ...

  8. Makefile总结和反序字符数组,整体右移数组,杨辉三角!

    2015.1.23今天我值日 继续接着昨天Makefile的目标开始记录:第一种:有 .PHNOY声明,但是冒号后面没有依赖文件.PHNOY:clean clean://没有依赖文件 rm *.0 t ...

  9. 【LeetCode】Best Time to Buy and Sell Stock IV

    Best Time to Buy and Sell Stock IV Say you have an array for which the ith element is the price of a ...

  10. simple grammer

    <?phpecho strlen("Hello world!"); // outputs 12?> <?phpecho str_word_count(" ...