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 ...
随机推荐
- 从头開始学 RecyclerView(六) LayoutManager
前言 在前面的文章中.每一个演示样例,都使用了LayoutManager,毕竟它是RecyclerView必不可少的一部分. LayoutManager,顾名思义,就是『布局管理器』. 使用例如以下代 ...
- IIS服务器支持.apk文件下载
随着智能手机的普及,越来越多的人使用手机上网,很多网站也应手机上网的需要推出了网站客户端,.apk文件就是安卓(Android)的应用程序后缀名,默认情况下,使用IIS作为Web服务器的无法下载此文件 ...
- TensorFlow 入门 上(自用)
下文会出现的一些知识点:TensorFlow的计算模型.数据模型.运行模型,TensorFlow的工作原理. 两个重要概念——Tensor和Flow: Tensor是张量,在TensorFlow中可以 ...
- 清除linux系统的多余引导
由于我把系统给升级(update)了,在grub引导模式出现新旧版本(Grub与Grub2)的引导系统分别为正常启动和进入恢复模式各2个引导项,如下图显示:百度找不到相关或类似的教程,只好半夜起来研究 ...
- JS实现的MAP结构数据
Array.prototype.remove = function(s) { for (var i = 0; i < this.length; i++) { if (s == this[i]) ...
- CentOS6网卡静态IP设置
CentOS网卡配置源文件如下:DEVICE=eth0HWADDR=00:0C:29:A8:67:46TYPE=EthernetUUID=4103d7a8-d073-4e93-ac68-e6f8496 ...
- Linux使用sar进行性能分析
转:https://blog.csdn.net/xusensen/article/details/54606401#sar%E7%AE%80%E4%BB%8B Linux使用sar进行性能分析 Lin ...
- 【EasyUI】——EasyUI的布局
做一个站点首先要有站点的布局,所谓的布局事实上就是网页的排版.就是说你的网页显示时是什么样子的. 就比方百度的首页: 无论是谁登录.网页都是这个样式的. EasyUI中的网页布局一共分为五部分,分别为 ...
- leetCode 45.Jump Game II (跳跃游戏) 解题思路和方法
Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...
- MPMoviePlayerViewController 视频播放黑屏
MPMoviePlayerViewController 视频播放黑屏 今天用视频做本地视频播放:使用 MPMoviePlayerViewController 老是出现黑屏: 结果发现是一个 很坑爹的问 ...