題庫
00:00

16. Divide Two Integers

中等數學GoogleMicrosoft

Given two integers dividend and divisor, return their quotient truncated toward zero.

Prefer an implementation that does not use multiplication, division, or the modulo operator.

範例 1:

輸入: dividend = 10, divisor = 3
輸出: 3

範例 2:

輸入: dividend = 7, divisor = -3
輸出: -2

限制條件:

  • -2^31 <= dividend, divisor <= 2^31 - 1
  • divisor != 0
核心程式碼模式
● 已自動儲存第 1 行,第 1 欄