其他分享
首页 > 其他分享> > leetcode- 整数反转

leetcode- 整数反转

作者:互联网

# -*- coding: utf-8 -*-
"""
Created on Sat Jul 17 12:40:04 2021

@author: luogantt
"""

class Solution(object):
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        pp=1
        xs=list(str(x))
        if x<0:
            pp=-1
            xs=xs[1:]
    
        print(xs)
        n=len(xs)
        print(n)
        x1=0

        for p in range(n):
            print(int(xs[n-1-p])*10**(n-1))
            x1=x1+int(xs[n-1-p])*10**(n-p-1)
        return x1*pp
c=Solution()
a=12309
c1=c.reverse(a)

print('c1=',c1)
    

标签:pp,int,反转,coding,luogantt,Jul,整数,xs,leetcode
来源: https://blog.csdn.net/luoganttcc/article/details/118855247