mapto construct a graph. Note that for every
[b, a]should also be added.
valMapto store vals.
- Based case of DFS:
currhas been visited before. Return
- Params :
destknown from query
productcontains result (Next product should be
product * valmap.get(curr + '.' + neighbor)).
- While result from
-1, return it. Otherwise return -1.
You are given an array of variable pairs
equations and an array of real numbers
equations[i] = [Ai, Bi] and
values[i] represent the equation
Ai / Bi = values[i]. Each
Bi is a string that represents a single variable.
You are also given some
queries[j] = [Cj, Dj] represents the
jth query where you must find the answer for
Cj / Dj = ?.
Return the answers to all queries. If a single answer cannot be determined, return
Note: 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.
Input: equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]