Find that single one.(linear runtime complexity0
public class Solution {
public int singleNumber(int[] nums) {
int temp = 0;
for (int i=0;i<nums.length;i++)
{
temp = temp^nums[i];
}
return temp;
}
}
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?
Subscribe to see which companies asked this question
相异为1;找到相等的部分;为1的部分是不同的·
Find that single one.(linear runtime complexity0的更多相关文章
- [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 II(找出数组中只出现一次的数2)
问题: Given an array of integers, every element appears three times except for one. Find that single o ...
- [LeetCode] Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note: ...
- 【LeetCode】Single Number I & II & III
Single Number I : Given an array of integers, every element appears twice except for one. Find that ...
- Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Your al ...
- (Array,位操作)137. Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- 【leetcode】Single Number II (medium) ★ 自己没做出来....
Given an array of integers, every element appears three times except for one. Find that single one. ...
随机推荐
- MATLAB——解数独
数独 数独是一种逻辑游戏,玩家需要根据9x9盘面的已知数字,推理出剩余所有空格的数字,并满足每一行.每一列和每个粗线宫(3x3)内均含1~9,不重复. MATLAB中有关函数 M = dlmread( ...
- JS中的事件、事件冒泡和事件捕获、事件委托
https://www.cnblogs.com/diver-blogs/p/5649270.html https://www.cnblogs.com/Chen-XiaoJun/p/6210987.ht ...
- 制作新的train,test数据集
之前的数据集的train和test是直接按照网上下载的数据的前7000个作为训练集,后2212个作为测试集.看得出来,这个数据集是由开车录制视频转换来的图片数据,后面2000多个图片的场景和前面的场景 ...
- a标签目标链接问题
1.先确定开始文件和目标文件,例如从css.html开始到body.html 2.确定文件寻找路径,因为css.html的父目录是css,而body.html在body目录下,所以需要先退到上一目录h ...
- javaEE(7)_自定义标签&JSTL标签(JSP Standard Tag Library)
一.自定义标签简介 1.自定义标签主要用于移除Jsp页面中的java代码,jsp禁止出现一行java脚本. 2.使用自定义标签移除jsp页面中的java代码,只需要完成以下两个步骤: •编写一个实现T ...
- 设置tableview的滚动范围--iOS开发系列---项目中成长的知识三
设置tableview的滚动范围 有时候tableview的footerview上的内容需要向上拖动界面一定距离才能够看见, 项目中因为我需要在footerviw上添加一个按钮,而这个按钮又因为这个原 ...
- Greenplum/Deepgreen(单机/伪分布)安装文档
Greenplum/Deepgreen数据库安装(单机/伪分布) 首先去官网下载centos7:https://www.centos.org/download/,选择其中一个镜像下载即可,网上随意下载 ...
- Luogu P2664 树上游戏 dfs+树上统计
题目: P2664 树上游戏 分析: 本来是练习点分治的时候看到了这道题.无意中发现题解中有一种方法可以O(N)解决这道题,就去膜拜了一下. 这个方法是,假如对于某一种颜色,将所有这种颜色的点全部删去 ...
- 【OS_Linux】Linux系统中目录及文件管理
1.Linux系统中目录的树状结构 目录 /bin 存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里. /etc 存放系统管理和配置文件 /home 存放所有用户文件的根目录, ...
- 优化mysql查询
mysql提供了一个特别的explain语句,用来分析查询语句的性能 : explain select ... 1.在所有用于where,order by,group by的列上添加索引 创建索引 添 ...