Leetcode--136. Single Number(easy)
Given a non-empty 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?
Example 1:
Input: [2,2,1]
Output: 1
Example 2:
Input: [4,1,2,1,2]
Output: 4
class Solution {
public int singleNumber(int[] nums) {
int result=;
for(int i:nums){
result^=i;
}
return result;
}
}
silly solution
class Solution {
public int singleNumber(int[] nums) {
Map<Integer,Integer> mp=new HashMap<Integer,Integer>();
for(int i:nums){
mp.put(i,mp.getOrDefault(i,)+);
}
for(int i:mp.keySet()){
if(mp.get(i)<){
return i;
}
}
return ;
}
}
Leetcode--136. Single Number(easy)的更多相关文章
- LeetCode 136. Single Number C++ 结题报告
136. Single Number -- Easy 解答 相同的数,XOR 等于 0,所以,将所有的数字 XOR 就可以得到只出现一次的数 class Solution { public: int ...
- leetcode 136 Single Number, 260 Single Number III
leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...
- LeetCode 136. Single Number(只出现一次的数字)
LeetCode 136. Single Number(只出现一次的数字)
- leetcode 136. Single Number 、 137. Single Number II 、 260. Single Number III(剑指offer40 数组中只出现一次的数字)
136. Single Number 除了一个数字,其他数字都出现了两遍. 用亦或解决,亦或的特点:1.相同的数结果为0,不同的数结果为1 2.与自己亦或为0,与0亦或为原来的数 class Solu ...
- LeetCode 136 Single Number(仅仅出现一次的数字)
翻译 给定一个整型数组,除了某个元素外其余元素均出现两次. 找出这个仅仅出现一次的元素. 备注: 你的算法应该是一个线性时间复杂度. 你能够不用额外空间来实现它吗? 原文 Given an array ...
- [LeetCode] 136. Single Number 单独数
Given a non-empty array of integers, every element appears twice except for one. Find that single on ...
- LeetCode 136. Single Number (落单的数)
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- Leetcode 136 Single Number 仅出现一次的数字
原题地址https://leetcode.com/problems/single-number/ 题目描述Given an array of integers, every element appea ...
- LeetCode - 136. Single Number - ( C++ ) - 解题报告 - 位运算思路 xor
1.题目大意 Given an array of integers, every element appears twice except for one. Find that single one. ...
- leetcode 136 Single Number bBt Option
Linked Url:https://leetcode.com/problems/single-number/ Given a non-empty array of integers, every e ...
随机推荐
- c++ opencv 3.2 +Mfc VS2015窗体显示图片方法
本文仅涉及一些核心步骤,具体 OpenCV 的配置以及其他的细节问题,请参考 VS2010 / MFC + OpenCV 2.4.1打开图片. 1. 新建 MFC 对话框项目 基于对话框,不使用Uni ...
- git 标签管理
发布一个版本时,我们通常先在版本库中打一个标签(tag),这样,就唯一确定了打标签时刻的版本.将来无论什么时候,取某个标签的版本,就是把那个打标签的时刻的历史版本取出来.所以,标签也是版本库的一个快照 ...
- PAT 1046 划拳(15)(代码)
1046 划拳(15)(15 分) 划拳是古老中国酒文化的一个有趣的组成部分.酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字.如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢 ...
- MacDev.GetArchOfLibrary
1. static library How to check target architecture of a static library http://changhoward.blogspot.c ...
- p值还是 FDR ?
p值还是 FDR ? 差异分析 如何筛选显著性差异基因,p value, FDR 如何选 经常有同学询问如何筛选差异的基因(蛋白).已经计算了表达量和p value值,差异的基因(蛋白)太多了,如何筛 ...
- qrcode解决方案大全
QRCODE解决方案 1.delphi原生QRCode.pas 2.delphi编写http服务器实现QRcode请求生成图片,http下载 3.delphi编写cgi程序,加载到apache服务器 ...
- GCC编译的几个步骤
参考资料: https://blog.csdn.net/czg13548930186/article/details/78331692 一个C/C++文件要经过预处理(preprocessing).编 ...
- oracle导入sql文件关闭回馈
set feedback off --关闭回馈 set define off --关闭转义关键字
- 浅谈Spring中的Quartz配置
浅谈Spring中的Quartz配置 2009-06-26 14:04 樊凯 博客园 字号:T | T Quartz是一个强大的企业级任务调度框架,Spring中继承并简化了Quartz,下面就看看在 ...
- linux下导入导出数据库
导入导出数据库用mysqldump命令,使用方法与mysql命令类似. 导出 导出sql(包含数据和表结构):mysqldump -uroot -p dbname > dbname.sql 导出 ...