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 ...
随机推荐
- Linux执行命令时遇到的些问题
1.执行lsb_release -a,提示 未安装lsb_release导致的,执行一下yum install redhat-lsb -y,问题解决 2.配置tomcat站点后重启tomcat,提示找 ...
- windows netcdf vs 配置
程序中添加的头文件是netcdfcpp.h文件 ************************************************************************** ...
- Linux入门命令1
查询及帮助 man查看命令帮助,命令的词典,显示Unix联机参考手册的页面 info从Info参考系统中显示文件 help查看Linux内置命令的帮助,比如cd命令. whatis 为指定命令显示一行 ...
- 可以搜索局域网内的所有IP地址的软件
几乎都用现有的工具,直接扫描,这里我已python为例,搜索一下局域网内所有活动IP,基本原理就是ping,对返回的结果进行分析,从而判断对应ip是否活动,代码很简单,实验环境win10+python ...
- 采用JavaMelody监控Tomcat服务——安装手册
#1.获取安装包 .zip mv probe.war <tomcat dir>/webapps #3.设置tomcat用户信息 vi <tomcat dir>/conf/tom ...
- shell统计昨天的独立ip
test.txt --| --| --| --| --| --| --| --| --| shell命令 yesterday=`date +%Y-%m-%d -d -1days` awk -v yes ...
- lodash 中常用的方法
odash是js集Array/Object/String/Function的Util于一身. lodash打包了Array/Object/String/Function里一些Api,好处是连ES6的也 ...
- Properties of a scheduled job in Laravel
Every entry you add is converted into an instance of Illuminate\Console\Scheduling\Event and stored ...
- Previous Permutation
Similar to next permutation, the steps as follow: 1) Find k in the increasing suffix such that nums[ ...
- zookeeper相关
1.zookeeper应用:集群节点间的数据同步(资源管理),分布式锁(主要是利用客户端在一个会话中在zookeeper中创建一个znode节点,然后再去执行自己的业务代码,比如去更新数据库,其他客户 ...