Submitting the solution gives me stack overflow error when input is 0


  • 0
    E

    public class Solution {
    public int reverse(int x) {
    if(x<0)
    return -1reverse(-1x);
    int result =0;
    try
    {
    result = Integer.parseInt(new StringBuilder(String.valueOf(x)).reverse().toString());
    }
    catch(Exception e)
    { }
    return result;
    }
    }


Log in to reply
 

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