我无法通过这个问题的隐藏测试。有人能告诉我我的代码有什么问题吗?在
错误消息是:
"Execution time limit exceeded on test 7: Program exceeded the execution time limit. Make sure that it completes execution in a few seconds for any possible input."
我的代码:
def countSumOfTwoRepresentations2(n, l, r):
c=0
for i in range(l,r+1):
for j in range(l,i+1):
if(i+j==n):
c+=1
return(c)
我想你的问题是:
在代码中添加2个for循环可能会增加代码的时间复杂性,因为从您的角度来看,这是一种幼稚的方法。你应该试试这个:
在这个存储库中,您可以找到代码战斗街机解决方案
https://github.com/tigranv/Code_Fights_Solutions
相关问题 更多 >
编程相关推荐