Reverse Integer in python3


  • 0
    V

    class Solution(object):
    def reverse(self,a):
    t=False
    k=0

       if a<0:
         a=a*(-1)
         t=True
       temp=0
       while a>0:
          temp=temp*10+int(a%10)
          k=k+1
          
          a=int(a/10)
       if a<-pow(2,31) or a>pow(2,31)-1 or temp>pow(2,31)-1:
        return 0
       else:
           if t==True:
             return (-1*temp)
           else:
             return temp

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.