Solution in Ruby


  • 0
    C
    # @param {Integer} x
    # @return {Integer}
    def reverse(x)
        re_x=0
        if x<0
            is_negative=true
            x=0-x
        end
        
        temp_x=x
        while temp_x!=0
            re_x=re_x*10+temp_x%10
            temp_x=temp_x/10
        end
    
        if is_negative
            re_x=0-re_x
        end
        
        if re_x.bit_length >=32
            re_x=0
        end
        
        return re_x
    end
    

Log in to reply
 

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