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)/分式化简 [deep-dark-fraction].html
2022-03-29 12:43:11 +08:00

37 lines
1.4 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>有一个同学在学习分式。他需要将一个连分数化成最简分数,你能帮助他吗?</p>
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/09/09/fraction_example_1.jpg" style="height: 195px; width: 480px;" /></p>
<p>连分数是形如上图的分式。在本题中所有系数都是大于等于0的整数。</p>
<p> </p>
<p>输入的<code>cont</code>代表连分数的系数(<code>cont[0]</code>代表上图的<code>a<sub>0</sub></code>以此类推。返回一个长度为2的数组<code>[n, m]</code>,使得连分数的值等于<code>n / m</code>,且<code>n, m</code>最大公约数为1。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>cont = [3, 2, 0, 2]
<strong>输出:</strong>[13, 4]
<strong>解释:</strong>原连分数等价于3 + (1 / (2 + (1 / (0 + 1 / 2))))。注意[26, 8], [-13, -4]都不是正确答案。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>cont = [0, 0, 3]
<strong>输出:</strong>[3, 1]
<strong>解释:</strong>如果答案是整数令分母为1即可。</pre>
<p> </p>
<p><strong>限制:</strong></p>
<ol>
<li><code>cont[i] >= 0</code></li>
<li><code>1 <= cont的长度 <= 10</code></li>
<li><code>cont</code>最后一个元素不等于0</li>
<li>答案的<code>n, m</code>的取值都能被32位int整型存下即不超过<code>2 ^ 31 - 1</code>)。</li>
</ol>