1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/求解方程 [solve-the-equation].html
2022-03-29 12:43:11 +08:00

41 lines
1.5 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>求解一个给定的方程,将<code>x</code>以字符串 <code>"x=#value"</code>&nbsp;的形式返回。该方程仅包含 <code>'+'</code> <code>'-'</code> 操作,变量&nbsp;<code>x</code>&nbsp;和其对应系数。</p>
<p>如果方程没有解,请返回&nbsp;<code>"No solution"</code>&nbsp;。如果方程有无限解,则返回 <code>“Infinite solutions”</code></p>
<p>如果方程中只有一个解,要保证返回值 <font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.6px"><span style="background-color:#f9f2f4">'x'</span></span></font></font>&nbsp;是一个整数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong> equation = "x+5-3+x=6+x-2"
<strong>输出:</strong> "x=2"
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong> equation = "x=x"
<strong>输出:</strong> "Infinite solutions"
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong> equation = "2x=x"
<strong>输出:</strong> "x=0"
</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= equation.length &lt;= 1000</code></li>
<li><code>equation</code>&nbsp;只有一个&nbsp;<code>'='</code>.</li>
<li><code>equation</code>&nbsp;方程由整数组成,其绝对值在&nbsp;<code>[0, 100]</code>&nbsp;范围内,不含前导零和变量 <code>'x'</code>&nbsp;<span style="display:block"><span style="height:0px"><span style="position:absolute"></span></span></span></li>
</ul>