public class Solution { public int reverse(int x){ int flag=0; if(x==-2147483648){ return 0; } if(x<0){ x=-x; flag=1; } String temp1=x+""; double temp2=0.0; String temp3=""; Stack<Character> stack=new Stack<>(); char[] charArray=temp1.toCharArray(); for(int i=0;i<charArray.length;i++){ stack.push(charArray[i]); } while(!stack.empty()){ temp3+=stack.pop(); } temp2=Double.parseDouble(temp3); if(temp2>Integer.MAX_VALUE||temp2<Integer.MIN_VALUE){ return 0; } else{ if(flag==0) return (int)temp2; else return -(int)temp2; } }}
新闻热点
疑难解答