Divide Two Integers
MediumBit Manipulation & Math
Decode it first. Clues, constraints, pattern and plan before any code.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.
dividend = 10, divisor = 3 → 3
dividend = 7, divisor = -3 → -2
dividend = -2147483648, divisor = -1 → 2147483647 (clamped)Constraints
-2^31 <= dividend, divisor <= 2^31 - 1divisor != 0