Problem
Divide dividend by divisor without using multiplication, division, or the modulo operator, and return the quotient truncated toward zero (so 8.7 becomes 8 and -2.3 becomes -2).
The result must fit in a signed 32-bit integer: if the true quotient is greater than 2^31 - 1, return 2^31 - 1.
Example 1
- Input
- dividend = 10, divisor = 3
- Output
- 3
Example 2
- Input
- dividend = 7, divisor = -3
- Output
- -2
Example 3
- Input
- dividend = -2147483648, divisor = -1
- Output
- 2147483647
- Why
- clamped
Constraints
-2^31 <= dividend, divisor <= 2^31 - 1divisor != 0