LeetCode : 136. Single Number

原创 2016年08月29日 17:07:03

问题描述:

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?

分析:只要利用到 A^A = 0即可。

AC代码如下:

 int singleNumber(vector<int>& nums) 
    {
        int ans = 0;
        for(int i = 0;i < nums.size();i++)
        {
            ans = ans^nums[i];
        }
        return ans;
    }


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

<LeetCode OJ> 136 / 137 / 260 Single Number(I / II / III)

260. Single Number III My Submissions Question Total Accepted: 19802 Total Submissions: 47891 Di...

Leetcode No. 136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one.Note: ...

LeetCode P136 Single Number及异或知识

Given an array of integers, every element appears twice except for one. Find that single one. Note:...

Leetcode 136 Single Number 仅出现一次的数字

给出一个整数数组,除了某个元素外所有元素都出现两次。找出仅出现一次的数字。

LeetCode 136: Single Number 探讨

题目: Given an array of integers, every element appears twice except for one. Find that single one. N...

[LeetCode]--136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one.Note: ...

LeetCode 136 Single Number

题意给出一个整数数组,除了一个元素只出现一次,数组中的每个元素出现了两次,找出该元素 PS:线性的时间复杂度,能否不用额外空间完成?题解建立一个HashMap,键是整数元素,值是元素出现的次数。对数...

[LeetCode] 136--Single Number --Medium--

今天又来做题了,因为Find the Duplicate Number一直没想出来,但又不想直接上网看答案,只好做与它类似的题目。 Single NumberGiven an array of in...

leetcode 136. Single Number

/* leetcode 136. Single Number Given an array of integers, every element appears twice except for on...

leetcode(136)_Single Number

//每天各种生活琐事简直焦头烂额 //感觉毕业后就可以过上失业的生活了 //所以说被打乱节奏以至于还没找到工作的我对于“拥抱变化”神马的还是有点怨念 //其实还是自己的锅啦 //好像节奏有点慢...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)