Single Number

2017-08-29  本文已影响0人  文刀Hang

Given an array of integers, every element appearstwiceexcept for one. Find that single one.

Note:

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Answer:

class Solution(object):

    def singleNumber(self, nums):

        result = 0

        for num in nums:

            result ^= num#异或运算

        return result

上一篇 下一篇

猜你喜欢

热点阅读