540. Single Element in a Sorted Array

标签: leetcode 位操作
803人阅读 评论(5) 收藏 举报
分类:

原题

Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element that appears only once.

Example 1:
Input: [1,1,2,3,3,4,4,8,8]
Output: 2
Example 2:
Input: [3,3,7,7,10,11,11]
Output: 10

代码分析

异或操作求单数。

代码实现

        public int SingleNonDuplicate(int[] nums)
        {
            int rtn = nums[0];
            for(int i=1; i<nums.Length;i++)
            {
                rtn ^= nums[i];
            }
            return rtn;
        }
查看评论

LeetCode | 540. Single Element in a Sorted Array

540. Single Element in a Sorted Array DescriptionSubmissionsSolutions ...
  • pku_Coder
  • pku_Coder
  • 2017-03-18 11:42:46
  • 637

[LeetCode]540. Single Element in a Sorted Array

https://leetcode.com/problems/single-element-in-a-sorted-array/#/description Given a sorted array ...
  • Lakers_KobeBryant
  • Lakers_KobeBryant
  • 2017-05-09 18:49:39
  • 635

LeetCode 540. Single Element in a Sorted Array

这次随便找了一道题写,之前找了一道题,写了一个上午都没写出来就放弃了,一气之下就直接随便选了一道题写。话不多少之前看题吧。 ---------------------这是题目------------...
  • Ardenso
  • Ardenso
  • 2017-04-09 19:42:58
  • 498

{LeetCode} 540. Single Element in a Sorted Array

Given a sorted array consisting of only integers where every element appears twice except for one el...
  • sheldon0227
  • sheldon0227
  • 2017-03-21 11:51:17
  • 168

【LeetCode】540. Single Element in a Sorted Array

题目描述Given a sorted array consisting of only integers where every element appears twice except for on...
  • liao_zx
  • liao_zx
  • 2017-10-15 13:13:20
  • 79

540. Single Element in a Sorted Array(C++)

原題 Given a sorted array consisting of only integers where every element appears twice except for on...
  • qq_33469427
  • qq_33469427
  • 2017-09-26 12:01:37
  • 56

leetcode 540. Single Element in a Sorted Array

Given a sorted array consisting of only integers where every element appears twice except for one el...
  • huanghanqian
  • huanghanqian
  • 2017-07-17 16:46:18
  • 111

LeeCode 540. Single Element in a Sorted Array

LeeCode 540. Single Element in a Sorted Array
  • yong2201042k
  • yong2201042k
  • 2017-11-11 23:34:12
  • 18

[LeetCode] 540. Single Element in a Sorted Array

题目链接: https://leetcode.com/problems/single-element-in-a-sorted-array/description/ DescriptionGiven a...
  • Elliott_Yoho
  • Elliott_Yoho
  • 2017-12-04 15:17:21
  • 85

LeetCode-26 Remove Duplicates from Sorted Array(水题-去相同元素)

LeetCode-26 Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place...
  • u011035622
  • u011035622
  • 2015-04-29 17:29:39
  • 643
    算法channel

    交流思想,注重分析,实例阐述,通俗易懂,包含但不限于:经典算法,机器学习,深度学习,LeetCode 题解,Kaggle 实战。期待您的到来!

    算法与人工智能交流群:646901659

    个人资料
    专栏达人 持之以恒
    等级:
    访问量: 33万+
    积分: 7782
    排名: 3390
    博客专栏