Recursion limits [ref]
Problem¶
- Read Python's current recursion limit.
- Set the recursion limit to at least twice
n = 100plus10, without lowering its existing value. - Restore the saved limit afterward.
Python solution¶
import sys
original = sys.getrecursionlimit()
isinstance(original, int) # True
n = 100
sys.setrecursionlimit(max(original, 2 * n + 10))
sys.getrecursionlimit() >= 210 # True
sys.setrecursionlimit(original)
sys.getrecursionlimit() == original # True
Links¶
- 1192. Critical Connections in a Network (Graph Theory)