Description
Divide two integers without using multiplication, division, and mod operators. Return the integer quotient truncated toward zero.
Examples
Input:
dividend = 10, divisor = 3Output:
3Explanation:
10/3 = 3 truncated.
Input:
dividend = 7, divisor = -3Output:
-2Explanation:
Works with negative numbers.
Input:
dividend = -2147483648, divisor = -1Output:
2147483647Explanation:
This tests the integer overflow edge case. -2147483648 / -1 should equal 2147483648, but this exceeds the maximum 32-bit signed integer (2147483647), so the result is clamped to 2147483647.
Constraints
- •
-2³¹ ≤ dividend, divisor ≤ 2³¹ - 1