1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/两数相除 [divide-two-integers].html

33 lines
1.6 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你两个整数,被除数&nbsp;<code>dividend</code>&nbsp;和除数&nbsp;<code>divisor</code>。将两数相除,要求 <strong>不使用</strong> 乘法、除法和取余运算。</p>
<p>整数除法应该向零截断,也就是截去(<code>truncate</code>)其小数部分。例如,<code>8.345</code> 将被截断为 <code>8</code> <code>-2.7335</code> 将被截断至 <code>-2</code></p>
<p>返回被除数&nbsp;<code>dividend</code>&nbsp;除以除数&nbsp;<code>divisor</code>&nbsp;得到的 <strong></strong></p>
<p><strong>注意:</strong>假设我们的环境只能存储 <strong>32 位</strong> 有符号整数,其数值范围是 <code>[2<sup>31</sup>,&nbsp; 2<sup>31&nbsp;</sup> 1]</code> 。本题中,如果商 <strong>严格大于</strong> <code>2<sup>31&nbsp;</sup> 1</code> ,则返回 <code>2<sup>31&nbsp;</sup> 1</code> ;如果商 <strong>严格小于</strong> <code>-2<sup>31</sup></code> ,则返回 <code>-2<sup>31</sup></code><sup> </sup></p>
<p>&nbsp;</p>
<p><strong>示例&nbsp;1:</strong></p>
<pre>
<strong>输入:</strong> dividend = 10, divisor = 3
<strong>输出:</strong> 3
<strong>解释: </strong>10/3 = 3.33333.. ,向零截断后得到 3 。</pre>
<p><strong>示例&nbsp;2:</strong></p>
<pre>
<strong>输入:</strong> dividend = 7, divisor = -3
<strong>输出:</strong> -2
<strong>解释:</strong> 7/-3 = -2.33333.. ,向零截断后得到 -2 。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>-2<sup>31</sup> &lt;= dividend, divisor &lt;= 2<sup>31</sup> - 1</code></li>
<li><code>divisor != 0</code></li>
</ul>