zoukankan      html  css  js  c++  java
  • SingleNumber

    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?

    //意思是一堆数中找出没成对的那个,用异或效率最高A^0=A   A^A=0 最后可求出SingleNumber

    public class Solution {

        public int singleNumber(int[] A) {
            int res=0;
            for(int i=0;i<A.length;i++){
                res^=A[i];
            }
            return res;
        }
    }

  • 相关阅读:
    国王游戏
    选数
    双塔
    线段树
    树状数组及其他特别简单的扩展
    折半搜索
    VUE项目
    git_基本使用
    同源
    axios-使用
  • 原文地址:https://www.cnblogs.com/gaoxiangde/p/4379900.html
Copyright © 2011-2022 走看看