Skip to content

Practice Divide Two Integers

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#29
LeetCode Problem

Divide Two Integers

Problem Statement

Compute dividend divided by divisor without using multiplication, division or remainder operators. Discard the fractional part toward zero, so a negative result becomes less negative when truncated. Return the quotient within the signed 32-bit range [-2^31, 2^31 - 1]: clamp a result above the upper bound to 2^31 - 1 and a result below the lower bound to -2^31.

Source: Divide Two Integers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
dividend = 10, divisor = 3
Output
3

# Example 2

Input
dividend = 7, divisor = -3
Output
-2

Constraints

-2^31 <= dividend, divisor <= 2^31 - 1
divisor != 0

Related LeetCode Problems

Practice more problems similar to Divide Two Integers.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.