How to avoid StackOverflowError for a recursive function

后端 未结 6 1569
无人共我
无人共我 2021-01-01 18:19

I\'m writing a function that will call itself up to about 5000 times. Ofcourse, I get a StackOverflowError. Is there any way that I can rewrite this code in a f

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 19:10

    It's obvious that you get StackOverflow with such branching factor of your recursion. In other languages it can be achieved by Tail Call Optimization. But I suppose your problem needs another way to solve.

    Ideally, you perform some check on Block. Maybe you can obtain list of all blocks and check each of them iteratively?

提交回复
热议问题