Convert function from recursion to iteration

后端 未结 4 760
耶瑟儿~
耶瑟儿~ 2021-01-01 06:19

I have this function that I wrote that is abysmally slow since php does not handle recursion well. I am trying to convert it to a while loop, but am having trouble wrapping

4条回答
  •  醉话见心
    2021-01-01 06:58

    You can convert a recursive function into an iterative function by using a stack to store the current state. Look into array_push() and array_pop().

提交回复
热议问题