mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
55 lines
1.9 KiB
HTML
55 lines
1.9 KiB
HTML
<p>给定两个整数 <code>a</code> 和 <code>b</code> ,求它们的除法的商 <code>a/b</code> ,要求不得使用乘号 <code>'*'</code>、除号 <code>'/'</code> 以及求余符号 <code>'%'</code> 。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>注意:</strong></p>
|
||
|
||
<ul>
|
||
<li>整数除法的结果应当截去(<code>truncate</code>)其小数部分,例如:<code>truncate(8.345) = 8</code> 以及 <code>truncate(-2.7335) = -2</code></li>
|
||
<li>假设我们的环境只能存储 32 位有符号整数,其数值范围是 <code>[−2<sup>31</sup>, 2<sup>31</sup>−1]</code>。本题中,如果除法结果溢出,则返回 <code>2<sup>31 </sup>− 1</code></li>
|
||
</ul>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>a = 15, b = 2
|
||
<strong>输出:</strong>7
|
||
<strong><span style="white-space: pre-wrap;">解释:</span></strong>15/2 = truncate(7.5) = 7
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>a = 7, b = -3
|
||
<strong>输出:</strong><span style="white-space: pre-wrap;">-2</span>
|
||
<strong><span style="white-space: pre-wrap;">解释:</span></strong>7/-3 = truncate(-2.33333..) = -2</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>a = 0, b = 1
|
||
<strong>输出:</strong><span style="white-space: pre-wrap;">0</span></pre>
|
||
|
||
<p><strong>示例 4:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>a = 1, b = 1
|
||
<strong>输出:</strong><span style="white-space: pre-wrap;">1</span></pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>-2<sup>31</sup> <= a, b <= 2<sup>31</sup> - 1</code></li>
|
||
<li><code>b != 0</code></li>
|
||
</ul>
|
||
|
||
<p> </p>
|
||
|
||
<p>注意:本题与主站 29 题相同:<a href="https://leetcode-cn.com/problems/divide-two-integers/">https://leetcode-cn.com/problems/divide-two-integers/</a></p>
|
||
|
||
<p> </p>
|