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 (22 loc) · 618 Bytes

File metadata and controls

24 lines (22 loc) · 618 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;
/**反转整数
* 内存溢出时返回0
* Integer范围
* +2147483647
* -2147483648
* @author JunjunYang
* @date 2019/12/18 12:02
*/
public class ReverseInt {
public int reverse(int x) {
int sum = 0;
while (x != 0) {
int mod = x % 10;
x /= 10;
if (sum > Integer.MAX_VALUE / 10 || (sum == Integer.MAX_VALUE / 10 && mod > 7)) return 0;
if (sum < Integer.MIN_VALUE / 10 || (sum == Integer.MIN_VALUE / 10 && mod < -8)) return 0;
sum = sum * 10 + mod;
}
return sum;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.