Medium

Quiz

#29 Divide Two Integers

APPROACH

Compute the quotient of dividing dividend by divisor without multiplication, division, or modulo. Truncate toward zero and clamp the result to the 32-bit signed integer range [-231, 231 - 1].

Example 1:

Input: dividend = 10, divisor = 3
Output: 3
Explanation: 10/3 = 3.33333.. which is truncated to 3.

Example 2:

Input: dividend = 7, divisor = -3
Output: -2
Explanation: 7/-3 = -2.33333.. which is truncated to -2.
1 of 4
1:00

What is the optimal approach for this problem?