Help Debug, Please


  • 0
    Y

    public int reverse(int x) {
    if(x > Integer.MAX_VALUE || x < Integer.MIN_VALUE){
    return 0;
    }
    int y = Math.abs(x);
    String s = Integer.toString(y);
    // s = String.valueOf(y);
    StringBuilder sb = new StringBuilder();
    int len = s.length();
    for(int i=len-1; i>=0; i--){
    sb.append(s.charAt(i));
    }
    String st = sb.toString();
    int res = Integer.valueOf(st);
    if(res > Integer.MAX_VALUE){
    return 0;
    }
    return x>0 ? res: -res;
    }


Log in to reply
 

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