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)/等式方程的可满足性 [satisfiability-of-equality-equations].html
2022-03-29 12:43:11 +08:00

53 lines
2.0 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>equations[i]</code> 的长度为 <code>4</code>,并采用两种不同的形式之一:<code>&quot;a==b&quot;</code>&nbsp;<code>&quot;a!=b&quot;</code>。在这里a 和 b 是小写字母(不一定不同),表示单字母变量名。</p>
<p>只有当可以将整数分配给变量名,以便满足所有给定的方程时才返回&nbsp;<code>true</code>,否则返回 <code>false</code>&nbsp;</p>
<p>&nbsp;</p>
<ol>
</ol>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>[&quot;a==b&quot;,&quot;b!=a&quot;]
<strong>输出:</strong>false
<strong>解释:</strong>如果我们指定a = 1 且 b = 1那么可以满足第一个方程但无法满足第二个方程。没有办法分配变量同时满足这两个方程。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>[&quot;b==a&quot;,&quot;a==b&quot;]
<strong>输出:</strong>true
<strong>解释:</strong>我们可以指定 a = 1 且 b = 1 以满足满足这两个方程。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>[&quot;a==b&quot;,&quot;b==c&quot;,&quot;a==c&quot;]
<strong>输出:</strong>true
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>[&quot;a==b&quot;,&quot;b!=c&quot;,&quot;c==a&quot;]
<strong>输出:</strong>false
</pre>
<p><strong>示例 5</strong></p>
<pre><strong>输入:</strong>[&quot;c==c&quot;,&quot;b==d&quot;,&quot;x!=z&quot;]
<strong>输出:</strong>true
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ol>
<li><code>1 &lt;= equations.length &lt;= 500</code></li>
<li><code>equations[i].length == 4</code></li>
<li><code>equations[i][0]</code>&nbsp;<code>equations[i][3]</code>&nbsp;是小写字母</li>
<li><code>equations[i][1]</code> 要么是&nbsp;<code>&#39;=&#39;</code>,要么是&nbsp;<code>&#39;!&#39;</code></li>
<li><code>equations[i][2]</code>&nbsp;&nbsp;<code>&#39;=&#39;</code></li>
</ol>