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 ...
随机推荐
- jquery分页插件精选
1.最新的分页控件:Mricode.Pagination(推荐) https://github.com/mricle/Mricode.Pagination 2.Jquery Pagination Pl ...
- vue 环境搭建
目前我们的项目前端都采用的是vue js为了方便开发过程中前后端同事进行功能对接,建议每个同事都准备好前后端环境(前端的同事参考文档第二部分,后端同事请参考第一部分),只要保持前后端代码是最新的就可以 ...
- PHP——explode的应用(获取字符串,拆为下拉列表)
<?php //定义有默认值的函数 function Main3($f=5,$g=6) { echo $f*$g; } Main3(2,3); echo "<br />&q ...
- java8 数据结构的改变(一)
在JDK1.6,JDK1.7中,HashMap采用数组+链表实现,即使用链表处理冲突,同一hash值的链表都存储在一个链表里.但是当数组中一个位置上的元素较多,即hash值相等的元素较多时,通过key ...
- Android.InstallAntOnMacOSX
在Mac OS X上安装ant http://blog.csdn.net/crazybigfish/article/details/18215439
- 搭建http静态网页服务器出现“Forbidden You don't have permission to access / on this server”
部分参考链接: 2.4+ httpd最简单example.conf, 存放目录:/etc/httpd/conf.d/example.conf Alias /newstart-zte/ "/n ...
- 转:百度MySql5.7安装配置
原文地址:http://jingyan.baidu.com/article/8cdccae946133f315513cd6a.html MySQL 5.7以上版本的配置和以前有所不同,在这里与大家分享 ...
- Vue router 全局路由守卫
记录一下全局路由守卫的使用: 方法一:定义一个数组用于检测与管理需要登录的页面,全局路由守卫配合本地存储判断是否跳转 import Vue from 'vue' import Router from ...
- centos安装tomcat7.0.70
抄自:https://www.cnblogs.com/www1707/p/6592504.html apache-tomcat-7.0.70jdk-7u67-linux-x64 下载tomcathtt ...
- Git使用基础篇(zz)
Git使用基础篇 您的评价: 收藏该经验 Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体 ...