https://leetcode.com/explore/interview/card/top-interview-questions-easy/127/strings/880/
풀이
class Solution:
def reverse(self, x: int) -> int:
x = list(str(x))
x.reverse()
if x[-1] == '-':
x = int('-' + "".join(x[0:-1]))
else:
x = int("".join(x))
max_num = 2**31
if x > max_num or x < -max_num:
return 0
return x
반응형
'Algorithm > Online judge' 카테고리의 다른 글
[LeetCode] Strings > Valid Palindrome (0) | 2021.05.25 |
---|---|
[LeetCode] Strings > Valid Anagram (0) | 2021.05.25 |
[백준] 15868번 > 치킨 배달 (0) | 2021.05.20 |
[백준] 14500번 > 테트로미노 (0) | 2021.05.19 |
[백준] 1009번 > 분산처리 (0) | 2021.05.18 |