Skip to content

Commit ba62b7e

Browse files
committed
Create README - LeetHub
1 parent 7d3fddf commit ba62b7e

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Diff for: evaluate-division/README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<h2>399. Evaluate Division</h2><h3>Medium</h3><hr><div><p>You are given an array of variable pairs <code>equations</code> and an array of real numbers <code>values</code>, where <code>equations[i] = [A<sub>i</sub>, B<sub>i</sub>]</code> and <code>values[i]</code> represent the equation <code>A<sub>i</sub> / B<sub>i</sub> = values[i]</code>. Each <code>A<sub>i</sub></code> or <code>B<sub>i</sub></code> is a string that represents a single variable.</p>
2+
3+
<p>You are also given some <code>queries</code>, where <code>queries[j] = [C<sub>j</sub>, D<sub>j</sub>]</code> represents the <code>j<sup>th</sup></code> query where you must find the answer for <code>C<sub>j</sub> / D<sub>j</sub> = ?</code>.</p>
4+
5+
<p>Return <em>the answers to all queries</em>. If a single answer cannot be determined, return <code>-1.0</code>.</p>
6+
7+
<p><strong>Note:</strong> The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong>Example 1:</strong></p>
11+
12+
<pre><strong>Input:</strong> equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]
13+
<strong>Output:</strong> [6.00000,0.50000,-1.00000,1.00000,-1.00000]
14+
<strong>Explanation:</strong>
15+
Given: <em>a / b = 2.0</em>, <em>b / c = 3.0</em>
16+
queries are: <em>a / c = ?</em>, <em>b / a = ?</em>, <em>a / e = ?</em>, <em>a / a = ?</em>, <em>x / x = ?</em>
17+
return: [6.0, 0.5, -1.0, 1.0, -1.0 ]
18+
</pre>
19+
20+
<p><strong>Example 2:</strong></p>
21+
22+
<pre><strong>Input:</strong> equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]]
23+
<strong>Output:</strong> [3.75000,0.40000,5.00000,0.20000]
24+
</pre>
25+
26+
<p><strong>Example 3:</strong></p>
27+
28+
<pre><strong>Input:</strong> equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]]
29+
<strong>Output:</strong> [0.50000,2.00000,-1.00000,-1.00000]
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= equations.length &lt;= 20</code></li>
37+
<li><code>equations[i].length == 2</code></li>
38+
<li><code>1 &lt;= A<sub>i</sub>.length, B<sub>i</sub>.length &lt;= 5</code></li>
39+
<li><code>values.length == equations.length</code></li>
40+
<li><code>0.0 &lt; values[i] &lt;= 20.0</code></li>
41+
<li><code>1 &lt;= queries.length &lt;= 20</code></li>
42+
<li><code>queries[i].length == 2</code></li>
43+
<li><code>1 &lt;= C<sub>j</sub>.length, D<sub>j</sub>.length &lt;= 5</code></li>
44+
<li><code>A<sub>i</sub>, B<sub>i</sub>, C<sub>j</sub>, D<sub>j</sub></code> consist of lower case English letters and digits.</li>
45+
</ul>
46+
</div>

0 commit comments

Comments
 (0)