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
标签:divisor,int,09,29,相除,dividend 来源: https://blog.csdn.net/qq_44833392/article/details/120598935