#29
Divide Two Integers
expert · 1260 · lc medium +32 · verified · 19.4% accepted · 6,067 likes · top 1%
Description
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.
Code
1
2
3