#question : 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? class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
intlen=len(nums)
if intlen == 0:
return -1
if intlen == 1:
return nums[0] ans=nums[0]
for i in range(1,intlen):
ans = ans ^ nums[i] return ans
相关文章
- [LeetCode&Python] Problem 283. Move Zeroes
- LeetCode算法题-Prime Number of Set Bits in Binary Representation(Java实现)
- 【LeetCode】831. Masking Personal Information 解题报告(Python)
- 【LeetCode】108. Convert Sorted Array to Binary Search Tree 解题报告 (Java & Python)
- LeetCode之“数学”:Happy Number
- 【LeetCode】140. Word Break II 解题报告(Python & C++)
- python安装包提示error: option --single-version-externally-managed not recognized
- [LeetCode]题解(python):062-Unique Paths
- LeetCode Letter Combinations of a Phone Number 电话号码组合
- LeetCode461 Hamming Distance java The Hamming distance between two integers is the number osoluotion