|
11 | 11 |
|
12 | 12 | ## 399. Evaluate Division (Medium) |
13 | 13 |
|
14 | | -<p> |
15 | | -Equations are given in the format <code>A / B = k</code>, where <code>A</code> and <code>B</code> are variables represented as strings, and <code>k</code> is a real number (floating point number). Given some queries, return the answers. If the answer does not exist, return <code>-1.0</code>. |
16 | | -</p> |
17 | | -<p><b>Example:</b><br/> |
18 | | -Given <code> a / b = 2.0, b / c = 3.0.</code> <br/>queries are: <code> a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? .</code> <br/>return <code> [6.0, 0.5, -1.0, 1.0, -1.0 ].</code> |
19 | | -</p> |
20 | | -<p> |
21 | | -The input is: <code> vector<pair<string, string>> equations, vector<double>& values, vector<pair<string, string>> queries </code>, where <code>equations.size() == values.size()</code>, and the values are positive. This represents the equations. Return <code> vector<double></code>. |
22 | | -</p> |
23 | | - |
24 | | -<p>According to the example above: |
25 | | -<pre>equations = [ ["a", "b"], ["b", "c"] ], |
| 14 | +<p>Equations are given in the format <code>A / B = k</code>, where <code>A</code> and <code>B</code> are variables represented as strings, and <code>k</code> is a real number (floating point number). Given some queries, return the answers. If the answer does not exist, return <code>-1.0</code>.</p> |
| 15 | + |
| 16 | +<p><b>Example:</b><br /> |
| 17 | +Given <code> a / b = 2.0, b / c = 3.0.</code><br /> |
| 18 | +queries are: <code> a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? .</code><br /> |
| 19 | +return <code> [6.0, 0.5, -1.0, 1.0, -1.0 ].</code></p> |
| 20 | + |
| 21 | +<p>The input is: <code> vector<pair<string, string>> equations, vector<double>& values, vector<pair<string, string>> queries </code>, where <code>equations.size() == values.size()</code>, and the values are positive. This represents the equations. Return <code> vector<double></code>.</p> |
| 22 | + |
| 23 | +<p>According to the example above:</p> |
| 24 | + |
| 25 | +<pre> |
| 26 | +equations = [ ["a", "b"], ["b", "c"] ], |
26 | 27 | values = [2.0, 3.0], |
27 | | -queries = [ ["a", "c"], ["b", "a"], ["a", "e"], ["a", "a"], ["x", "x"] ]. </pre> |
28 | | -</p> |
| 28 | +queries = [ ["a", "c"], ["b", "a"], ["a", "e"], ["a", "a"], ["x", "x"] ]. </pre> |
| 29 | + |
| 30 | +<p> </p> |
29 | 31 |
|
30 | | -<p> |
31 | | -The input is always valid. You may assume that evaluating the queries will result in no division by zero and there is no contradiction. |
32 | | -</p> |
| 32 | +<p>The input is always valid. You may assume that evaluating the queries will result in no division by zero and there is no contradiction.</p> |
33 | 33 |
|
34 | 34 | ### Related Topics |
35 | 35 | [[Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)] |
|
0 commit comments