Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
24 lines (20 loc) · 637 Bytes

File metadata and controls

24 lines (20 loc) · 637 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package leetcode.string;
public class ReverseNum {
public static void main(String[] args) {
int x = -12300;
System.out.println(reverseNum(x));
}
public static int reverseNum(Integer x) {
int result = 0;
while (x != 0) {
// 因为都是用int型的,如果超出了范围,其除以10的结果就不会跟之前的结果一致,通过这点也可以进行区分
int tmp = result * 10 + x % 10;
if (tmp / 10 != result) {
return 0;
}
result = tmp;
x = x / 10;
}
return result;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.