-1
def has22(nums):
if nums[len(nums) - 1] == 2:
if nums[len(nums) - 2] == 2:
return True
else:
for n in range(len(nums) - 3):
if nums[n] == 2 :
if nums[n + 1] == 2:
return True
else:
return False
我需要返回True,如果数组包含2旁边的2某处。但它给了我一个错误:“列表索引超出范围”。我应该改变什么?CodingBat has22为什么这个解决方案是错误的?
我很新的东西,所以可能我的代码是最长的解决方法之一,但我感谢任何帮助。谢谢!
你能否粘贴整个错误? – Bharel