MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / divide

Method divide

Number/DivideTwoIntegers.py:37–53  ·  view source on GitHub ↗

:type dividend: int :type divisor: int :rtype: int

(self, dividend, divisor)

Source from the content-addressed store, hash-verified

35"""
36class Solution(object):
37 def divide(self, dividend, divisor):
38 """
39 :type dividend: int
40 :type divisor: int
41 :rtype: int
42 """
43
44 x = abs(dividend) // abs(divisor)
45 if (dividend < 0 and divisor > 0) or (dividend > 0 and divisor < 0):
46
47 if -x < -2**31:
48 return -2**31
49 return -x
50
51 if x > 2**31-1:
52 return 2**31-1
53 return x
54

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected