问题是: 给定一个整数数组,查找并打印可从数组中选择的最大整数数,以使所选整数中任意两个的绝对差小于或等于1
def pickingNumbers(a):
maxi=0
for i in a:
x=a.count(i)
y=a.count(i-1)
x=x+y
if x>maxi :
maxi=x
print(maxi)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
a = list(map(int, input().rstrip().split()))
result = pickingNumbers(a)
fptr.write(str(result) + '\n')
fptr.close()
给定输入:
6
4 6 5 3 3 1
预期输出:3
我的输出:None
在
pickingNumbers
的末尾打印maxi的值,而不是返回它由于没有显式返回值,因此函数返回
None
,该值被转换为str(result)
中的字符串'None'
只需更换:
你应该没事的
相关问题 更多 >
编程相关推荐