cjql / algorithm

https://cjql.github.io/algorithm/
1 stars 1 forks source link

top100: single-number #18

Open cjql opened 4 years ago

cjql commented 4 years ago

https://leetcode.com/problems/single-number

C++

Java

Python

class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        return reduce(operator.xor, nums)

88 ms | 16.4 MB | python3

class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        res = 0
        for num in nums:
            res ^= num
        return res

80 ms | 16.2 MB

C

C

JavaScript

Ruby

Swift

Go

Scala

Kotlin

Rust

PHP