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 }
  • 相关阅读:
    2
    1
    java10
    java8
    java9
    java7
    java6
    java5
    java4
    java3
  • 原文地址:https://www.cnblogs.com/lishiblog/p/4179349.html
Copyright © 2011-2022 走看看