题解 | #数组中只出现一次的两个数字#
数组中只出现一次的两个数字
http://www.nowcoder.com/practice/389fc1c3d3be4479a154f63f495abff8
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param array int整型一维数组
# @return int整型一维数组
#
class Solution:
def FindNumsAppearOnce(self , array ):
# write code here
array_sorted = sorted(array)
result = []
i = 0
if len(array) == 2:
if array[0] != array[1]:
return array
else:
return
else:
while(i <= len(array_sorted)-1):
if i == len(array_sorted)-1:
result.append(array_sorted[i])
i = i + 1
elif array_sorted[i] == array_sorted[i+1]:
i = i + 2
else:
result.append(array_sorted[i])
i = i + 1
if len(result) == 2:
return result
else:
return