29. 两数相除

'''
Author: 365JHWZGo
Description: 29. 两数相除
Date: 2021-09-30 11:09:00
FilePath: \Python\test\demo2.py
LastEditTime: 2021-10-03 21:46:11
LastEditors: 365JHWZGo29. 
'''
class Solution(object):
    def divide(self, dividend, divisor):
        """
        :type dividend: int
        :type divisor: int
        :rtype: int
        """
        if (dividend<0 and divisor>0) or (dividend>0 and divisor<0):
            r = abs(dividend)/abs(divisor)
            r =  (-1)*int(r)
            if r<=-2**31:
                return -2**31
            else:
                return r
        else:
            r = int(dividend/divisor)
            if r>=2**31-1:
                return 2**31-1
            else:
                return r
上一篇:【LeetCode-29】两数相除


下一篇:Leetcode - 29. 两数相除