Flood Fill Algorithm Python

前端 未结 3 1286
孤城傲影
孤城傲影 2020-12-29 14:42

So I\'m trying to create a flood fill algorithm and I keep getting a recursion error with this. The algorithm seems to have infinite recursion and I cannot pinpoint why. I

3条回答
  •  太阳男子
    2020-12-29 15:20

    Instead of recursion, why not flood-fill in a depth-first manner? Recursion uses an implicit stack anyway so you've nothing to lose.

    And yes, as pointed out in the comments, you should be checking for x and y being out of bounds.

提交回复
热议问题