Solution for Easy 121 without recursion