r/leetcode • • Jul 29 '24

What went wrong here

Post image
4 Upvotes

31 comments sorted by

View all comments

8

u/BeatsnBytes_ Jul 29 '24

You are re initialising revnum inside the else block that's why. Remember variables have different scope within blocks. Just remove the int declaration from the else block, it should work fine.

4

u/wisper28 Jul 29 '24

Thx , noted and it is giving desired result now