Reversing integer using python:Easy to understand


  • 0
    K

    class Solution:
    def reverse(self, x):
    """
    :type x: int
    :rtype: int
    """
    rev=0
    counter=0
    if(x<0):
    counter=1
    x=-x
    while(x>0):
    rev=(rev*10)+(x%10)
    x=x//10
    if rev>=2147483647:#32 bit integer start value or use (7FFF,FFFF)16
    return 0
    if(counter==1):
    return (-rev)
    else:
    return (rev)


Log in to reply
 

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