我测试我的代码为“查找唯一编号”,我遇到Codewars中止:进程已终止。它需要较长的时间比12000ms完成
STDERR:
Process was terminated. It took longer than 12000ms to complete
SIGKILL Process exited prematurely with a SIGKILL signal. Server Execution Error:
The server timed out waiting for the code to finish executing. It is possible that this is due to high server load. It may also be caused by inefficent code. Please try your request again.
这经常出现我的代码。这与代码质量有关,还是服务器问题?我希望它引用我的代码。
find_uniq = lambda a: [x for x in a if a.count(x) == 1].pop()
# I have passed all of this tests
# btw I'm using python 3
test.assert_equals(find_uniq([ 1, 1, 1, 2, 1, 1 ]), 2)
test.assert_equals(find_uniq([ 0, 0, 0.55, 0, 0 ]), 0.55)
test.assert_equals(find_uniq([ 3, 10, 3, 3, 3 ]), 10)
Time: 92ms Passed: 3 Failed: 0
“这也可以通过inefficent代码造成的。”在真实的环境中运行你的代码。完成时间是否超过12秒? – Carcigenicate
这看起来像你的代码被太慢的服务器杀死。您可以尝试将您的'find_uniq'函数提交给https://codereview.stackexchange.com/以获得提高速度的帮助。 –
您发布的代码中没有任何内容可以解释长运行时间。即使92ms似乎也相当长。 –