关闭

540. Single Element in a Sorted Array

标签: leetcode位操作
793人阅读 评论(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;
        }
2
0
查看评论

[LeetCode]540. Single Element in a Sorted Array

https://leetcode.com/problems/single-element-in-a-sorted-array/#/description Given a sorted array consisting of only integers where every element ap...
  • Lakers_KobeBryant
  • Lakers_KobeBryant
  • 2017-05-09 18:49
  • 543

LeetCode | 540. Single Element in a Sorted Array

540. Single Element in a Sorted Array DescriptionSubmissionsSolutions Total Accepted: 1638 ...
  • pku_Coder
  • pku_Coder
  • 2017-03-18 11:42
  • 586

540. Single Element in a Sorted Array

Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element...
  • SHURamos
  • SHURamos
  • 2017-03-19 22:07
  • 220

【编程题】Single Element in a Sorted Array

/**************** 思想:    抑或操作 复杂度:     O(n) ************************/ int singleNonDuplicate(vector& nums) { int size =...
  • u013291818
  • u013291818
  • 2017-05-31 20:40
  • 191

LeetCode 540. Single Element in a Sorted Array

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

【LeetCode】540. Single Element in a Sorted Array

题目描述Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single ele...
  • liao_zx
  • liao_zx
  • 2017-10-15 13:13
  • 67

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

原題 Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single ele...
  • qq_33469427
  • qq_33469427
  • 2017-09-26 12:01
  • 45

LeeCode 540. Single Element in a Sorted Array

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

leetcode 540. Single Element in a Sorted Array

Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element...
  • huanghanqian
  • huanghanqian
  • 2017-07-17 16:46
  • 96

[LeetCode] 540. Single Element in a Sorted Array

题目链接: https://leetcode.com/problems/single-element-in-a-sorted-array/description/ DescriptionGiven a sorted array consisting of only integers where ev...
  • Elliott_Yoho
  • Elliott_Yoho
  • 2017-12-04 15:17
  • 67
    算法channel

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

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

    个人资料
    • 访问:319462次
    • 积分:7589
    • 等级:
    • 排名:第3380名
    • 原创:350篇
    • 转载:1篇
    • 译文:0篇
    • 评论:58条
    博客专栏