【发布时间】:2020-01-15 14:37:49
【问题描述】:
我正在寻找以下代码的指导。我正在学习 Python,我来自 Java 和 C#,我是初学者。我想编写一个函数,它返回出现奇数次的数字。假设数组总是大于 1,并且总是只有一个整数出现奇数次。我想使用递归。
该函数不返回值,因为当我存储结果时我得到一个 NoneType。拜托,我不是在寻找解决方案,而是在寻找调试时的位置和思考方式的一些建议。
def find_it(seq):
seqSort = seq
seqSort.sort()
def recurfinder(arg,start,end):
seqSort = arg
start = 0
end = seqSort.length()-1
for i in range(start,end):
counter = 1
pos = 0
if seqSort[i+1] == seqSort[i]:
counter+=1
pos = counter -1
else:
if(counter % 2 == 0):
recurfinder(seqSort, pos+1, end)
else:
return seqSort[i]
return -1
【问题讨论】:
-
请格式化您的代码
-
对于所有与 python 相关的问题,请始终使用通用 [python] 标签。自行决定使用特定于版本的标签。请注意,通常假定 Python 3 是因为 Python 2 正迅速接近其生命周期的终点。
-
理解,抱歉,谢谢