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 ...
随机推荐
- Unity的shader学习1
先来看一段我们项目常见的Shader代码,这个是Vertex&Fragment shader,目前已经不常用了,不过还是适合我们理解一些基础知识和理解一些比较老的shader 代码.下次我们再 ...
- iOS:Xcode7以上版本安装镜像文件.dmg
Xcode:7.0~7.3的镜像如下,点击直接下载安装 xcode7.0:https://developer.apple.com/services-account/download?path=/Dev ...
- getaddrinfo详解
#include <sys/socket.h> #include <netdb.h> int getaddrinfo(const char *restrict nodename ...
- MD5在线查询的实现
#!/usr/bin/env python # -*- coding: UTF-8 -*- ''' 快速查询md5值工具,通过模拟浏览器发包请求http://cmd5.com和 http://xmd5 ...
- VC++多线程--进程间通信
1.邮槽 邮槽是windows系统提供的一种单向通信的机制,邮槽能传输的数据非常小,一般在400k左右. 创建邮槽 HANDLE CreateMailslot( LPCTSTR lpName, //指 ...
- js中的this基础
this在js中的地位可以说是相当高了,本文介绍下this的基本相关情况,以后还会慢慢介绍 在页面中aler(this)//this的指向是window 在DOM操作中this的指向是当前发生事件的对 ...
- PHP防抓取数据curl 解决方法
1.使用Snoopy或curl传搜索引擎爬虫的USERAGENT值. 查看搜索引擎爬虫的USERAGENT值:http://www.cnblogs.com/grimm/p/5068092.html ( ...
- uva 10518 - How Many Calls?(矩阵快速幂)
题目链接:uva 10518 - How Many Calls? 公式f(n) = 2 * F(n) - 1, F(n)用矩阵快速幂求. #include <stdio.h> #inclu ...
- 使用mocha测试
学习了MOCHA官网的示例,将学习成果记录一下.[原文+例子:使用mocha测试] mocha是什么 Mocha是一个跑在node和浏览器上的javascript测试框架,让异步测试变得简单有趣, 并 ...
- BI项目简单备份策略
在项目的开发中,备份是一个很重要的操作和良好的开发习惯,下面我们就针对BI相关项目的备份说一下备份策略 前端:Cognos 后端:SSIS+View+Procedure 服务器A装了Cognos内容库 ...