美文网首页
136. Single Number

136. Single Number

作者: 衣介书生 | 来源:发表于2018-04-07 22:07 被阅读6次

    题目分析

    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?
    思路参考

    代码

    public class Solution {
        public int singleNumber(int[] A) {
            int res = 0;
            for(int a : A) {
                res ^= a;
            }
            return res;
        }
    }
    

    相关文章

      网友评论

          本文标题:136. Single Number

          本文链接:https://www.haomeiwen.com/subject/nbzzqftx.html