will you check the input i == 0?
I don't understand why people keep pasting their code here. your code is super slow and implemented the algorithm in a very stupid way. why not just to go home and try to optimize your code? A trivial java version can finish it in 3ms.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.