【LeetCode-面试算法经典-Java实现】【136-Single Number(仅仅出现一次的数字)】
【136-Single Number(仅仅出现一次的数字)】
【LeetCode-面试算法经典-Java实现】【全部题目文件夹索引】
原题
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?
题目大意
给定一个数组,每一个元素都出现2次除了当中的一个。找出仅仅出现一次的数字注意:算法必须是线性时间复杂度,能够不使用额外空间实现吗?
解题思路
使用异或运算。
代码实现
算法实现类
public class Solution {
public int singleNumber(int[] nums) {
if (nums == null || nums.length < 1) {
throw new IllegalArgumentException("nums");
}
for (int i = 1; i< nums.length; i++) {
nums[0] ^= nums[i];
}
return nums[0];
}
}
评測结果
点击图片。鼠标不释放。拖动一段位置。释放后在新的窗体中查看完整图片。
特别说明
欢迎转载。转载请注明出处【http://blog.csdn.net/derrantcm/article/details/47745389】
【LeetCode-面试算法经典-Java实现】【136-Single Number(仅仅出现一次的数字)】的更多相关文章
- LeetCode 136. Single Number(只出现一次的数字)
LeetCode 136. Single Number(只出现一次的数字)
- Leetcode 136 Single Number 仅出现一次的数字
原题地址https://leetcode.com/problems/single-number/ 题目描述Given an array of integers, every element appea ...
- 【LeetCode-面试算法经典-Java实现】【139-Word Break(单词拆分)】
[139-Word Break(单词拆分)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a string s and a dictionary of w ...
- 【LeetCode-面试算法经典-Java实现】【010-Regular Expresssion Matching(正則表達式匹配)】
[010-Regular Expresssion Matching(正則表達式匹配)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Implement regular ...
- 【LeetCode-面试算法经典-Java实现】【053-Maximum Subarray(最大子数组和)】
[053-Maximum Subarray(最大子数组和)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Find the contiguous subarray w ...
- LeetCode 136. Single Number C++ 结题报告
136. Single Number -- Easy 解答 相同的数,XOR 等于 0,所以,将所有的数字 XOR 就可以得到只出现一次的数 class Solution { public: int ...
- 【LeetCode-面试算法经典-Java实现】【062-Unique Paths(唯一路径)】
[062-Unique Paths(唯一路径)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 A robot is located at the top-left c ...
- 【LeetCode-面试算法经典-Java实现】【059-Spiral Matrix II(螺旋矩阵II)】
[059-Spiral Matrix II(螺旋矩阵II)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given an integer n, generate a ...
- leetcode 136 Single Number, 260 Single Number III
leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...
随机推荐
- 从零开始学JavaScript二(基本概念)
基本概念 一.区分大小写 在ECMAScript中的一切(变量.函数名.操作符)都是区分大小写的. 如变量名test和Test分别表示两个不同的变量, 二.标识符 所谓标识符,就是指变量.函数.属性的 ...
- HDOJ 4686 Arc of Dream 矩阵高速幂
矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/ ...
- 远程binlog
binlog介绍 binlog,即二进制日志,它记录了数据库上的所有改变. 改变数据库的SQL语句执行结束时,将在binlog的末尾写入一条记录,同时通知语句解析器,语句执行完毕. binlog格式 ...
- Codeforces B - Berland National Library
B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...
- windows 安装 docker
.https://download.docker.com/win/stable/InstallDocker.msi .设置环境变量 C:\Program Files (x86)\Git\bin .如果 ...
- Bootstrap系列 -- 15. 下拉选择框select【转发】
<form role="form"> <div class="form-group"> <select class="f ...
- 【Spark】RDD操作具体解释3——键值型Transformation算子
Transformation处理的数据为Key-Value形式的算子大致能够分为:输入分区与输出分区一对一.聚集.连接操作. 输入分区与输出分区一对一 mapValues mapValues:针对(K ...
- HTTP协议详解之URL篇
•HTTP URL基本格式: <http://host[:port][abs_path] / [;parameters][?query]#fragment> 1)http:表示要通过HTT ...
- 链接、ip地址及端口号
# encoding=utf-8 #python 2.7.10 #xiaodeng #链接(即报文如何通过传输控制协议链接从一个地方搬移到另外一个地方) #HTTP权威指南 13页 #TCP/IP # ...
- Linux下MySQL链接被防火墙阻止
Linux下安装了MySQL,不能从其它机器访问 帐号已经授权从任意主机进行访问 vi /etc/sysconfig/iptables 在后面添加 -A RH-Firewall-1-INPUT -m ...