Question
Given a 32-bit signed integer, reverse digits of an integer.
대충 해석
주어빈 32비트 int를 뒤집어보세요
Example
1
2
3
4
5
6
7
8
9
10
11
#1
Input:123
Output: 321
#2
Input: -123
Output: -321
#3
Input: 120
Output: 21
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class ReverseInteger {
public static void main(String[] args) {
// LeetCode Easy 7
int input = 1534236469;
long rev = 0;
while(input != 0) {
long temp =(rev * 10) + (input % 10);
rev = (temp - (input % 10)) / 10 != rev ? 0 : temp;
input /= 10;
}
System.out.println(rev);
}
}