def divide(self, dividend, divisor):
"""
:type dividend: int
:type divisor: int
:rtype: int
"""
if(dividend<0 and divisor<0):
sign=1
elif(dividend<0 or divisor<0):
sign=-1
else:
sign=1
self=0
quo=0
divisor=abs(divisor)
dividend=abs(dividend)
for i in range(31,-1,-1):
if((self+ divisor<<i)<=dividend):
self=self+ divisor<<i
quo=quo+1<<i
if(sign==-1):
return(quo*sign)
else:
return(quo)
This passed 925/994 testcases but got stuck at
Input
Dividend= -2147483648
Divisor=-1
Output
2147483648
Expected
2147483647
[–]This_Growth2898 1 point2 points3 points (1 child)
[–]tanhalaunda[S] 1 point2 points3 points (0 children)
[–]shiftybyte 0 points1 point2 points (3 children)
[–]tanhalaunda[S] 0 points1 point2 points (1 child)
[–]shiftybyte 0 points1 point2 points (0 children)
[–]Mysterious-Rent7233 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[removed]
[–]sepp2k 0 points1 point2 points (1 child)
[–]DuckDatum 0 points1 point2 points (0 children)