You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
570 B
21 lines
570 B
'''
|
|
给出一个有符号正整数,你需要将这个整数中每位上的数字进行反转。
|
|
示例 1: 输入: 123 输出: 321
|
|
示例 2: 输入: 714 输出: 417
|
|
示例 3: 输入: 120 输出: 21
|
|
'''
|
|
|
|
class Solution(object):
|
|
def reverse(self,x):
|
|
"""
|
|
:type x: int
|
|
:rtype: int
|
|
"""
|
|
ans = 0
|
|
while x:
|
|
ans = ans*10 + x%10 # 不断取x/10的余数
|
|
x //= 10
|
|
if x < 1: break
|
|
return ans
|
|
|
|
print ( Solution().reverse( 123 ) ) |