[LeetCode][Python3] 7. Reverse Integer
2018. 9. 11. 22:05 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/reverse-integer/description/
My Solution :
class Solution:
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
sign = 1
if x < 0:
sign = -1
x = -x
result = 0
while x:
result = 10*result + x % 10
x //= 10
if 2**31 < result:
return 0
return sign * result
Comment :
문자열로 변환하지 않고 풀어야 의미가 있는 문제.
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 35. Search Insert Position (0) | 2018.09.12 |
---|---|
[LeetCode][Python3] 28. Implement strStr() (0) | 2018.09.12 |
[LeetCode][Python3] 27. Remove Element (0) | 2018.09.11 |
[LeetCode][Python3] 26. Remove Duplicates from Sorted Array (0) | 2018.09.11 |
[LeetCode][Python3] 21. Merge Two Sorted Lists (0) | 2018.09.11 |
[LeetCode][Python3] 20. Valid Parentheses (0) | 2018.09.11 |
[LeetCode][Python3] 14. Longest Common Prefix (0) | 2018.09.11 |
[LeetCode][Python3] 13. Roman to Integer (0) | 2018.09.11 |
최근에 달린 댓글 최근에 달린 댓글