zoukankan      html  css  js  c++  java
  • Leetcode-Single Number

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

    Analysis:

    Use XOR operation.

    Solution:

     1 public class Solution {
     2     public int singleNumber(int[] A) {
     3         if (A.length==0) return -1;
     4         int res = A[0];
     5         for (int i=1;i<A.length;i++)
     6             res = res^A[i];
     7         return res;
     8         
     9     }
    10 }
  • 相关阅读:
    2017.8.07
    2017.8.05
    2017.8.04
    2017.8.03
    2017.8.02
    2017.8.01
    2017.7.31
    2017.7.29
    2017.7.28
    简易日历
  • 原文地址:https://www.cnblogs.com/lishiblog/p/4179349.html
Copyright © 2011-2022 走看看