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 ...
随机推荐
- 关于由CSS2.1所提出的的BFC的理解与样例
今天在这里谈谈css中BFC.“BFC”是Block Formatting Context的缩写,这个概念是由CSS2.1提出来的,它决定了元素如何对其内容进行定位,以及与其他元素的关系和相互作用.满 ...
- asp.net MVC code first Migrations : Model 同步到DB中
找来找去,看来用这个功能的人很少. http://www.it165.net/pro/html/201403/10653.html 步骤: 1,在程序包管理控制台上,Enable-Migrations ...
- NLPIR(ICTCLAS)分析包的使用记录
前段时间使用了HanLP一个纯JAVA分词工具包,后来老大说分词效果不是很好,需要换一个分词工具.于是推荐了一个分词工具——NLPIR,它是中科院XXX研发的一个分词工具.这个分词工具只用C/C++写 ...
- AngularJs angular.identity和angular.noop详解
angular.identity 函数返回本身的第一个参数.这个函数一般用于函数风格. ----------以上是官网对该接口的说明,只能说这个文档写得也太二,让人完全看不懂.要理解它的用途,可直接看 ...
- javascript中的克隆
一:节点克隆 var p = document.getElementsByTagName("p")[0]; var cP = p.cloneNode();//克隆p节点 var c ...
- 集成SDK查看包架构指令
1.查看支持构架的命令是lipo -info xxxxx.a 2.合并真机和模拟器的库的命令是 lipo -create xxxx_iphoneos.a xxxx_simulator.a -outpu ...
- Android数据存储-读取内部存储空间数据
内部存储空间的默认位置 data/data/应用名称 写数据,获取FileOutPutStream的方式 1.直接写死路径的方式 FileOutputStream fos = new FileOutp ...
- ansible安装httpd
--- - hosts: web tasks: - name: "INSTALL" yum: name={{ item }} state=pres ...
- software_testing_work3_question2
package com.Phantom; import java.rmi.server.Operation; import java.util.Scanner; public class Work3_ ...
- softwareTesting_work2_question1
input类 package com.Phantom; import java.util.ArrayList; import java.util.HashMap; import java.util.L ...