本文共 392 字,大约阅读时间需要 1 分钟。
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?使用异或运算,XOR!!!
大杀器!!!本来我想使用unordered_map的,但是需要额外的空间。
class Solution { //using xorpublic: int singleNumber(vector & nums) { int res=nums[0]; for(int i=1;i
转载地址:http://eexvi.baihongyu.com/