RecursionError: maximum recursio

2021-12-22  本文已影响0人  candice0430

When you execute a recursive function in Python on a large input ( > 10^4), you might encounter a “maximum recursion depth exceeded error”. This is a common error when executing algorithms such as DFS, factorial, etc. on large inputs. This is also common in competitive programming on multiple platforms when you are trying to run a recursive algorithm on various test cases. 

例如:

解决方案:Using the setrecursionlimit() method, we can increase the recursion limit and the program can be executed without errors even on large inputs.

import sys

sys.setrecursionlimit(10**6)

上一篇 下一篇

猜你喜欢

热点阅读