题目链接:https://leetcode.com/problems/single-number/

题目: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?

解题思路:题意为:给定一个数组。仅仅有一个元素出现了一次。其他元素都出现了两次,找出那个仅仅出现一次的数。

能够遍历数组。分别进行异或运算。

注:异或运算:同样为0,不同为1。遍历并异或的结果就是那个仅仅出现了一次的数。

演示样例代码:

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

【LeetCode OJ 136】Single Number的更多相关文章

  1. 【LeetCode OJ 268】Missing Number

    题目链接:https://leetcode.com/problems/missing-number/ 题目:Given an array containing n distinct numbers t ...

  2. 【LeetCode算法-9】Palindrome Number

    LeetCode第9题 Determine whether an integer is a palindrome. An integer is a palindrome when it reads t ...

  3. 【Leetcode 136】Single Number

    问题描述:给出一个整数数组,除了一个元素外,其他每个元素都出现了2次,找出只出现1次的元素. int singleNumber(vector<int>& nums); 分析:比较自 ...

  4. 【LeetCode OJ 016】3Sum Closest

    题目链接:https://leetcode.com/problems/3sum-closest/ 题目:Given an array S of n integers, find three integ ...

  5. LeetCode(136) Single Number

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

  6. 【LeetCode OJ 232】Implement Queue using Stacks

    题目链接:https://leetcode.com/problems/implement-queue-using-stacks/ 题目:Implement the following operatio ...

  7. 【LeetCode OJ 34】Search for a Range

    题目链接:https://leetcode.com/problems/search-for-a-range/ 题目:Given a sorted array of integers, find the ...

  8. 【LeetCode OJ 14】Longest Common Prefix

    题目链接:https://leetcode.com/problems/longest-common-prefix/ 题目:Write a function to find the longest co ...

  9. 【leetcode 字符串处理】Compare Version Numbers

    [leetcode 字符串处理]Compare Version Numbers @author:wepon @blog:http://blog.csdn.net/u012162613 1.题目 Com ...

随机推荐

  1. 网络简要<入门篇>对应配置代码

    交换机的配置 (1)交换机的模式: switch>    用户模式,可以查看设备的部分内容 SW-3ceng>enable SW-3ceng#          进入特权模式,可以查看更多 ...

  2. Kali linux 2016.2(Rolling)之 Nessus安装及Plugins Download Fail 解决方法

    最近,因科研需要,学习Nessus. Nessus是一款优秀的漏洞扫描软件,在其v6 HOME版本中在线更新漏洞插件不成功,采用离线更新,成功地更新了插件,在此将更新方法进行分享. 1.Nessus软 ...

  3. NPOI导出Excel自动计算公式问题

    以前用过sheet.ForceFormulaRecalculation = true;当时能够自动计算出来. 今天把模板改了一下(没动公式,但是模板是老板改的,我也不知道他操作了什么),结果就不能自动 ...

  4. Foeach 时修改集合的值报错

    就是"集合已修改:可能无法执行枚举操作 foreach" 啥的, 不让我改 百度到Foreach是只读的,只供取值用,无法进行新增,修改,删除(仅引用,实际待验证) 解决办法:将F ...

  5. 图片懒加载插件echo.js——改造

    今天做一个列表项需要用到懒加载,搜到网友推荐的echo.js,试用了一下,还不错.除了懒加载,还提供了throttle——节流,即用户快速滑动列表时,很快滑过的项的图片不会加载,只会加载最后停下来的位 ...

  6. php知识点(基本上文档都有,只为方便记忆)

    类型转换 (unset)转换为NULL (binary) 转换和 b 前缀转换支持为 PHP 5.2.1 新增   转换二进制 隐藏php后缀名 AddType application/x-httpd ...

  7. vue 上滑加载更多

    移动端网页的上滑加载更多,其实就是滑动+分页的实现. <template> <div> <p class="footer-text">--{{f ...

  8. turn.js中文API 写一个翻页效果的参数详细解释

    $('.flipbook').turn({     width: 922,     height: 600,     elevation: 50,     gradients: true,     a ...

  9. Django--form组件cookie/session

    Field required=True, 是否允许为空 widget=None, HTML插件 label=None, 用于生成Label标签或显示内容 initial=None, 初始值 help_ ...

  10. typora与Markdown的一些小问题

    一.typora中修改图像大小 加上style="zoom:50%" <img src="E:\GitHub_learn\blog\source\imgs\tree ...