Given an array of integers, every element appears twice except for one. Find that single one.Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

  线性时间完成,不花费多余空间,问题特殊,异或运算就解决了。

public class Solution {
public int singleNumber(int[] nums) {
int result = 0;
for(int num: nums)
{
result^=num;
}
return result;
}
}

Single Number的更多相关文章

  1. [LeetCode] Single Number III 单独的数字之三

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...

  2. [LeetCode] Single Number II 单独的数字之二

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

  3. [LeetCode] Single Number 单独的数字

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

  4. LeetCode Single Number I / II / III

    [1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...

  5. LeetCode——Single Number II(找出数组中只出现一次的数2)

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

  6. [LintCode] Single Number 单独的数字

    Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Have you met this question in ...

  7. 【LeetCode】Single Number I & II & III

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

  8. LeetCode 【Single Number I II III】

    Given an array of integers, every element appears twice except for one. Find that single one. 思路: 最经 ...

  9. Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference

    最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...

  10. Leetcode 137. Single Number I/II/III

    Given an array of integers, every element appears twice except for one. Find that single one. 本题利用XO ...

随机推荐

  1. 如何使用.NET开发全版本支持的Outlook插件产品(二)——完善插件

    插件项目所有代码都已经上传至 https://github.com/VanPan/TestOutlookAdding 勿在浮砂筑高台--定位错误 在介绍后面的插件开发技术之前,让我们先来看看已经达到的 ...

  2. 例子:Background Audio Streamer Sample

    The Background Audio Streamer sample demonstrates how to create an app that uses a MediaStreamSource ...

  3. 【1】springmvc4 + servlet3 零配置全注解入门项目helloword

    自从servlet3.0支持注解,使得javaweb项目使用全注解成为可能. 注解化将成为javaweb的发展方向.包括spring去年推出的spring-boot也是全部使用注解. 代码:https ...

  4. git pull错误

    1. Pull is not possible because you have unmerged files. 症状:pull的时候 $ git pull Pull is not possible ...

  5. Java优化

    Java初级优化 1. 对于明确不需要派生的类,添加final修饰符,此时该类的所有方法都是final的.Java编译器会寻找机会内联(inline)所有的final方法.(能使性能提升50%)2. ...

  6. 北大poj-2688

    Cleaning Robot Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4395   Accepted: 1763 De ...

  7. C#中datatable导出excel(三种方法)

    方法一:(拷贝直接可以使用,适合大批量资料, 上万笔) Microsoft.Office.Interop.Excel.Application appexcel = new Microsoft.Offi ...

  8. BZOJ 1018 线段树维护图连通性

    用8个bool维护即可分别为LURU,LURD,LDRU,LDRD,LULD,RURD,Side[1],Side[2]即可. Side表示这一块有没有接到右边.Merge一下就可以了.码农题,WA了一 ...

  9. Tomcat8 localhost+端口可以访问Manager APP,而IP+端口不可以访问 解决办法

    localhost + 端口可以正常访问Manager APP,而IP + 端口不能访问Manager APP,报403错误.(我的主机环境是Ubuntu16.04) 前提是你已经配好了tomcat_ ...

  10. linux /boot 清理

    随着升级 /boot分区会越来越满 导致后续无法升级  原因是因为每次升级有可能升级内核  但是旧的内核没有删除  所以导致/boot一直增大 解决办法就是删除不需要的内核,一下步骤: 查看所有安装的 ...