Solution in python3


  • 0
    A
    
    def reverse(a):
        try:
            out_str = ''
            if isinstance(a, int):
                a = str(a)
            if a[0] == '-':
                out_str += '-'
            for i in range(len(a)-1, -1, -1):
                if a[i] != '-':
                    out_str += a[i]
            return int(out_str)
        except:
            return 'That is an invalid input.'
    
    

Log in to reply
 

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