1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-27 18:50:26 +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 Normal View History

2023-12-09 18:42:21 +08:00
<p>给你两个整数,被除数&nbsp;<code>dividend</code>&nbsp;和除数&nbsp;<code>divisor</code>。将两数相除,要求 <strong>不使用</strong> 乘法、除法和取余运算。</p>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<p>整数除法应该向零截断,也就是截去(<code>truncate</code>)其小数部分。例如,<code>8.345</code> 将被截断为 <code>8</code> <code>-2.7335</code> 将被截断至 <code>-2</code></p>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<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>
2022-03-27 20:56:26 +08:00
<p>&nbsp;</p>
<p><strong>示例&nbsp;1:</strong></p>
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong> dividend = 10, divisor = 3
2022-03-27 20:56:26 +08:00
<strong>输出:</strong> 3
2023-12-09 18:42:21 +08:00
<strong>解释: </strong>10/3 = 3.33333.. ,向零截断后得到 3 。</pre>
2022-03-27 20:56:26 +08:00
<p><strong>示例&nbsp;2:</strong></p>
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong> dividend = 7, divisor = -3
2022-03-27 20:56:26 +08:00
<strong>输出:</strong> -2
2023-12-09 18:42:21 +08:00
<strong>解释:</strong> 7/-3 = -2.33333.. ,向零截断后得到 -2 。</pre>
2022-03-27 20:56:26 +08:00
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
2023-12-09 18:42:21 +08:00
<li><code>-2<sup>31</sup> &lt;= dividend, divisor &lt;= 2<sup>31</sup> - 1</code></li>
<li><code>divisor != 0</code></li>
2022-03-27 20:56:26 +08:00
</ul>