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)/两数相除 [xoh6Oh].html

55 lines
1.9 KiB
HTML
Raw 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>给定两个整数 <code>a</code><code>b</code> ,求它们的除法的商 <code>a/b</code> ,要求不得使用乘号 <code>&#39;*&#39;</code>、除号 <code>&#39;/&#39;</code> 以及求余符号 <code>&#39;%&#39;</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>注意:</strong></p>
<ul>
<li>整数除法的结果应当截去(<code>truncate</code>)其小数部分,例如:<code>truncate(8.345) = 8</code>&nbsp;以及&nbsp;<code>truncate(-2.7335) = -2</code></li>
<li>假设我们的环境只能存储 32 位有符号整数,其数值范围是 <code>[&minus;2<sup>31</sup>,&nbsp;2<sup>31</sup>&minus;1]</code>。本题中,如果除法结果溢出,则返回 <code>2<sup>31&nbsp;</sup>&minus; 1</code></li>
</ul>
<p>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>-2<sup>31</sup>&nbsp;&lt;= a, b &lt;= 2<sup>31</sup>&nbsp;- 1</code></li>
<li><code>b != 0</code></li>
</ul>
<p>&nbsp;</p>
<p>注意:本题与主站 29&nbsp;题相同:<a href="https://leetcode-cn.com/problems/divide-two-integers/">https://leetcode-cn.com/problems/divide-two-integers/</a></p>
<p>&nbsp;</p>