Why my solution is error?


  • 0
    L
    static int reverse(int x) {
    	String str = "";
    	int result = 0;
    	int flag = 1;
    	if(x < 0){
    		x = Math.abs(x);
    		flag = -1;
    	}
    	String xx = String.valueOf(x);
    	for(int i=xx.length()-1; i>=0; i--){
    		System.out.println(xx.charAt(i));
    		str += xx.charAt(i);
    	}
    	result = Integer.parseInt(str);
        return result*flag;
    }
    

    description the error


  • 0
    N

    The output should be 1 I think, but I also think there should be a better way to solve this problem


Log in to reply
 

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