Leetcode
2020.04.28 06:21

# 7. Reverse Integer

조회 수 106 추천 수 0 댓글 0
?

#### 단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

#### 단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

Given a 32-bit signed integer, reverse digits of an integer.

Example 1:

```Input: 123
Output: 321
```

Example 2:

```Input: -123
Output: -321
```

Example 3:

```Input: 120
Output: 21
```

Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

```class Solution {
public int reverse(int x) {
int result = 0;

while (x != 0) {
int last = x % 10;
x /= 10;

if(result > Integer.MAX_VALUE/10){
return 0;
}

if(result == Integer.MAX_VALUE/10 && last > 7){
return 0;
}

if (result < Integer.MIN_VALUE/10){
return 0;
}

if(result == Integer.MIN_VALUE/10 && last < -8){
return 0;
}

result = result * 10 + last;
}
return result;
}
}
```

?

 제목+내용제목내용댓글이름닉네임아이디태그
List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
77 Programmers hashmap 2020.04.30 0
76 Programmers fib 2020.04.30 0
75 Programmers team game 2020.04.30 0
74 Leetcode 692. Top K Frequent Words 2020.04.15 93
73 Leetcode 2. Add Two Numbers 2020.04.14 96
72 Leetcode 731. My Calendar II 2020.04.15 100
71 Leetcode 75. Sort Colors 2020.04.14 101
70 Leetcode 347. Top K Frequent Elements 2020.04.14 102
69 Leetcode 430. Flatten a Multilevel Doubly Linked List 2020.04.06 104
68 Leetcode 23. Merge k Sorted Lists 2020.04.14 104
67 Leetcode 729. My Calendar I 2020.04.15 104
66 Leetcode 253. Meeting Rooms II 2020.04.15 104
65 Leetcode 20. Valid Parentheses 2020.04.25 104
64 Leetcode 62. Unique Paths 2020.04.09 105
63 Leetcode 852. Peak Index in a Mountain Array 2020.04.28 106
» Leetcode 7. Reverse Integer 2020.04.28 106
61 Leetcode 946. Validate Stack Sequences 2020.04.08 107
60 Leetcode 973. K Closest Points to Origin 2020.04.15 107
59 Leetcode 350. Intersection of Two Arrays II 2020.04.28 108
58 Leetcode 443. String Compression 2020.04.25 109
Board Pagination Prev 1 2 3 4 Next
/ 4