-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleet7.java
More file actions
27 lines (26 loc) · 757 Bytes
/
Copy pathleet7.java
File metadata and controls
27 lines (26 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public int reverse(int x) {
int m = 1;
if(x<0){
m= - 1;
}
x = Math.abs(x);
String n = Integer.toString(x);
String str = new StringBuilder(n).reverse().toString();
System.out.println(str);
String check = "2147483647";
if(check.length() <= str.length()){
for(int i = 0; i < check.length() ; i++){
int ch = Integer.valueOf(check.charAt(i));
int strn = Integer.valueOf(str.charAt(i));
if(strn < ch){
break;
}
if(strn > ch){
return 0;
}
}
}
return m*Integer.valueOf(str);
}
}