Find that single one.(linear runtime complexity0
public class Solution {
public int singleNumber(int[] nums) {
int temp = 0;
for (int i=0;i<nums.length;i++)
{
temp = temp^nums[i];
}
return temp;
}
}
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?
Subscribe to see which companies asked this question
相异为1;找到相等的部分;为1的部分是不同的·
Find that single one.(linear runtime complexity0的更多相关文章
- [LeetCode] Single Number III 单独的数字之三
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...
- [LeetCode] Single Number II 单独的数字之二
Given an array of integers, every element appears three times except for one. Find that single one. ...
- [LeetCode] Single Number 单独的数字
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- LeetCode——Single Number II(找出数组中只出现一次的数2)
问题: Given an array of integers, every element appears three times except for one. Find that single o ...
- [LeetCode] Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note: ...
- 【LeetCode】Single Number I & II & III
Single Number I : Given an array of integers, every element appears twice except for one. Find that ...
- Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Your al ...
- (Array,位操作)137. Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- 【leetcode】Single Number II (medium) ★ 自己没做出来....
Given an array of integers, every element appears three times except for one. Find that single one. ...
随机推荐
- 什么是闭包(Closure)?
http://kb.cnblogs.com/page/111780/ 这个问题是在最近一次英格兰Brighton ALT.NET Beers活动中提出来的.我发现,如果不用代码来演示,你很难单用话语把 ...
- Swift REPL入门介绍
Xcode 6.1 引入了一个新特性用来辅助Swift开发,即Read Eval Print Loop(“读取-求值-输出”循环,简称REPL).熟悉解释型语言的开发者将会对这个命令行环境感到舒适,而 ...
- pathForResource获取资源为nil的原因
利用NSbundle获取 资源文件的时候,如果是自己添加的文件,获取的时候纵使返回nil的解决办法.原因是因为该文件没有添加到资源文件中,只要在添加文件的时候选择添加到 Create Folder R ...
- Webpack2 视频教程
原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」.Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本 ...
- gEdit - GTK+ 基础文本编辑器
语法 gedit [--help] [--version] [文件名] [文件名] [文件名] 等等... 描述 gEdit 是一个 X窗口系统下的基础文本编辑器由 GTK+ 写成.它现在支持建立,打 ...
- remote: Incorrect username or password ( access token ) fatal: Authentication failed for
gitee推送到远程仓库时提示错误remote: Incorrect username or password ( access token )fatal: Authentication failed ...
- 使用Microsoft Hadoop(一)
To run this program, stage some data in HDFS: 1. create a text file called input.txt that has one in ...
- React初识整理(二)--生命周期的方法
React生命周期主要有7中: 1. componentWillMount() :组件将要挂载时触发 ,只调用1次 2. componentDidMount() :组件挂载完成时触发,只调用1次 3. ...
- 蓝牙学习 (6) - Play with TI sensorTag (1)
硬件 cc2650 SensorTag Connect with App 在手机上安装Ti提供的sensorTag App即可和sensorTag 建立连接. 如下手机截图,
- 【Linux】VirtualBox虚拟网络配置
Host OS : Windows 10 Guest OS : CentOS 6.8 VirtualBox:5.1.18 网络连接方式: NAT 1.CentOS中使用DHCP [root@gouka ...