82. Single Number【easy】
Given 2*n + 1 numbers, every numbers occurs twice except one, find it.
Given [1,2,2,1,3,4,3], return 4
One-pass, constant extra space.
题意
给出2*n + 1 个的数字,除其中一个数字之外其他每个数字均出现两次,找到这个数字。
解法一:
class Solution {
public:
/*
* @param A: An integer array
* @return: An integer
*/
int singleNumber(vector<int> &A) {
int num = A[];
for (int i = ; i < A.size(); ++i) {
num ^= A[i];
}
return num;
}
};
利用异或的性质,相同为0
82. Single Number【easy】的更多相关文章
- 136. Single Number【LeetCode】异或运算符,算法,java
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- 491. Palindrome Number【easy】
Check a positive number is a palindrome or not. A palindrome number is that if you reverse the whole ...
- 170. Two Sum III - Data structure design【easy】
170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...
- 203. Remove Linked List Elements【easy】
203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...
- 88. Merge Sorted Array【easy】
88. Merge Sorted Array[easy] Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 ...
- 605. Can Place Flowers【easy】
605. Can Place Flowers[easy] Suppose you have a long flowerbed in which some of the plots are plante ...
- 485. Max Consecutive Ones【easy】
485. Max Consecutive Ones[easy] Given a binary array, find the maximum number of consecutive 1s in t ...
- 167. Two Sum II - Input array is sorted【easy】
167. Two Sum II - Input array is sorted[easy] Given an array of integers that is already sorted in a ...
- 283. Move Zeroes【easy】
283. Move Zeroes[easy] Given an array nums, write a function to move all 0's to the end of it while ...
随机推荐
- Mysql中DATE_SUB函数
在对数据查询或菜单时经常要对指定的时间或时间段进行查询,例如要查询一天内的信息,要查询一周内的信息,要查询一个月内的. 定义和用法 DATE_SUB() 函数从日期减去指定的时间间隔. 1.语法 DA ...
- linux开机启动的三种方式
参考:www.cnblogs.com/gzggyy/archive/2012/08/07/2626574.html 一./etc/rc.local 其中的rc.local是在完成所有的系统初始化之后执 ...
- Orchard运用 - 理解App_Data目录结构
了解一个系统,应该基本上要了解目录结构及其组织形式.这样对于开发人员更是必备的知识,比如开发模块最终安装到哪,主题Themes是如何配置启用. 今天跟大家分享其实是个笔记记录,就是看到有一篇文章介绍A ...
- jquery获取第一层li
<ul id="aaa"> <li>aaa</li> <li>aaa <ul> <li>bbb</li ...
- MIME简介
MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型.是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器 ...
- 【云计算】Docker容器不能修改hosts文件怎么解决?
参考资料: http://bbs.csdn.net/topics/390871429 http://tieba.baidu.com/p/4295556808 http://stackoverflow. ...
- Android之旅 自我图示总结四大组件
最近学完了Android的四大组件的基础知识,自己总结了一个图示,希望自己看到这个图的时候能回忆起相关的知识点,与大家分享!
- k-means聚类学习
4.1.摘要 在前面的文章中,介绍了三种常见的分类算法.分类作为一种监督学习方法,要求必须事先明确知道各个类别的信息,并且断言所有待分类项都有一个类别与之对应.但是很多时候上述条件得不到满足,尤其是在 ...
- poj 3311 Hie with the Pie dp+状压
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4671 Accepted: 2471 ...
- TP框架ajax U方法不解析怎么办?
TP框架中ajax U方法不解析 ajax U方法不解析 ajax url不解析 问题: 造成问题原因: Js 存在单独的 js文件中和html分离了.造成不解析! 解决方法: 方法一:将js放到ht ...