neetcode-gh / leetcode

Leetcode solutions
MIT License
5.61k stars 2.31k forks source link

Cleaner Solution for problem 0153 #3605

Closed Karthik-PM closed 4 weeks ago

Karthik-PM commented 2 months ago

The code to this problem is very unclean, there are unnecessary if statement in the first section of the while loop, with a break statement. The value of res is being written more than once in every case, even though, its only is needed to be put once. All of this makes the solution less understandable and unclean.

given solution:

image

My solution: image

Ykhan799 commented 4 weeks ago

@Karthik-PM Good Suggestion 👍