Single Number
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的更多相关文章
- [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 I / II / III
[1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...
- LeetCode——Single Number II(找出数组中只出现一次的数2)
问题: Given an array of integers, every element appears three times except for one. Find that single o ...
- [LintCode] Single Number 单独的数字
Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Have you met this question in ...
- 【LeetCode】Single Number I & II & III
Single Number I : Given an array of integers, every element appears twice except for one. Find that ...
- LeetCode 【Single Number I II III】
Given an array of integers, every element appears twice except for one. Find that single one. 思路: 最经 ...
- 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 ...
- Leetcode 137. Single Number I/II/III
Given an array of integers, every element appears twice except for one. Find that single one. 本题利用XO ...
随机推荐
- JDK安装与环境变量配置
1.安装JDK 选择安装目录 安装过程中会出现两次 安装提示 .第一次是安装 jdk ,第二次是安装 jre .建议两个都安装在同一个java文件夹中的不同文件夹中.(不能都安装在java文件夹的根目 ...
- The guard was taken to hospital in a critical condition.
The Prince George's County Fire Department said the guard was taken to hospital in a critical condit ...
- JQ源码学习-1-无new构建
此文章仅为个人学习 Aaron的jQuery源码分析 笔记之用. 一:采用 构造函数 返回 原型初始化方法,原型初始化方法又返回构造函数 的方式代替new 但当 返回的却是‘web’而不是Object ...
- iOS开发:保持程序在后台长时间运行
iOS开发:保持程序在后台长时间运行 2014 年 5 月 26 日 / NIVALXER / 0 COMMENTS iOS为了让设备尽量省电,减少不必要的开销,保持系统流畅,因而对后台机制采用墓碑式 ...
- C++中explicit关键字的使用
看书看到了explicit关键字,就来做个笔记,讲得比较明白,比较浅. 在C++中,我们有时可以将构造函数用作自动类型转换函数.但这种自动特性并非总是合乎要求的,有时会导致意外的类型转换,因此,C++ ...
- JS中setInterval与setTimeout的区别
JS里设定延时: 使用SetInterval和设定延时函数setTimeout 很类似.setTimeout 运用在延迟一段时间,再进行某项操作. setTimeout("function& ...
- Java的CLASSPATH,趁还没忘赶紧写点
咳咳,睡眠不足加上年龄增长,真的赶脚记忆力不行啦. 接触Java以来,对于环境配置就是按照网上的教程,一路复制粘贴,也没啥想法; 最近决定啃啃ThinkInJava,没看两章就看到这CLASSPATH ...
- Native VS React Native VS 微信小程序
随着React Native和 微信小程序的出现,Native一家独大的局面出现裂痕,很多小公司使用已经正在着手微信小程序和React Native了,我公司就已经走上React Native之路.那 ...
- 在VS的EF中连接MySQL
VS没有主动提供那些繁多的连接器,需要的话得自己再安装这些第三方程序包. MySQL为windows平台开发者提供了许多程序包:http://dev.mysql.com/downloads/windo ...
- C#获得网络连接信息 IPGlobalProperties
IPGlobalProperties 提供有关本地计算机的网络连接的信息. 此类提供有关本地计算机的网络接口和网络连接的配置和统计信息 可以获取本机TCP UDP 丢包 发包等数据. 此类提供的信息与 ...