29. Divide Two Integers

use bit manipulation 
class Solution(object):
    def divide(self, dividend, divisor):
        """
        :type dividend: int
        :type divisor: int
        :rtype: int
        """
        
        divd=abs(dividend)
        divr=abs(divisor) 
        result=0
        
        while divd>=divr:
            incr=divr 
            i=0
            while divd>=incr:
                divd-=incr
                result+=1<0) or (dividend>0 and divisor<0):
            return -result
        else: 
            return result

你可能感兴趣的:(29. Divide Two Integers)