class Solution:
“””
@param A : an integer array
@return : a integer
“””
def singleNumber(self, A):
# write your code here
# if not A:
# return 0
# for i in range(len(A)):
# for j in range(i + 1, len(A)):
# if A[i] > A[j]:
# A[i], A[j] = A[j], A[i]
# if len(A) < 2:
# return A[0]
# if A[0] != A[1]:
# return A[0]
# a = A[0]
# for i in range(1, len(A)):
# a = A[i] ^ a
# print(a)
# return A[a + 1] #返回的是数,不是坐标
#方法一:
# if not A:
# return 0
# a = A[0]
# for i in range(1, len(A)):
# a ^= A[i]
# return a
#方法二:
if not A:
return 0
if len(A) == 1:
return A[0]
for i in range(0, len(A)):
for j in range(i + 1, len(A)):
if A[i] > A[j]:
A[i], A[j] = A[j], A[i]
for i in range(0, len(A) - 1, 2):
if A[i] != A[i + 1]:
return A[i]
return A[-1]