3、整数反转-python

题目:https://leetcode-cn.com/problems/reverse-integer/

class Solution:
    def reverse(self, x: int) -> int:
        if x==0:
            return 0
        xa=-2147483648
        xb=2147483647
        s=str(x)
        if s[0]=='-':
            s=s.strip(s[0])
        s=s[::-1] #字符串逆序
        t=s
        for i in range(len(s)):
            if s[i]!='0':
                break
            else:
                t=s.strip(s[0]) 
        y=int(t)
        if x<0:
            y=-y
        if xa

 

你可能感兴趣的:(LeetCode)