Candy Crush


  • 0

    Click here to see the full article post


  • 0
    S

    @awice I have two questions: Firstly, although the function may call itself recursively, is it still true that we say it is a O(1) space? Secondly, would you please elaborate on time complexity O((R*C)^2). I do not get the square power completely.

    Thanks


  • 0
    S

    Great solution!

    It's O((R*C)^2) complexity because each function call scans the board three times so it's 3(R*C). If we only crush 3 candies each time, the function will be called (R*C)/3 times. Multiply those two terms together you get O((R*C)^2).


  • 0

    My similar solution though more verbose.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.