Skip to content

Commit 58f1227

Browse files
refaactor 399
1 parent 24bdcdb commit 58f1227

File tree

1 file changed

+2
-24
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-24
lines changed

src/main/java/com/fishercoder/solutions/_399.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,12 @@
66
import java.util.List;
77
import java.util.Map;
88

9-
/**
10-
* 399. Evaluate Division
11-
*
12-
* Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number).
13-
* Given some queries, return the answers. If the answer does not exist, return -1.0.
14-
15-
Example:
16-
Given a / b = 2.0, b / c = 3.0.
17-
queries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? .
18-
return [6.0, 0.5, -1.0, 1.0, -1.0 ].
19-
20-
The input is: vector<pair<string, string>> equations, vector<double>& values, vector<pair<string, string>> queries ,
21-
where equations.size() == values.size(), and the values are positive. This represents the equations. Return vector<double>.
22-
23-
According to the example above:
24-
25-
equations = [ ["a", "b"], ["b", "c"] ],
26-
values = [2.0, 3.0],
27-
queries = [ ["a", "c"], ["b", "a"], ["a", "e"], ["a", "a"], ["x", "x"] ].
28-
29-
The input is always valid. You may assume that evaluating the queries will result in no division by zero and there is no contradiction.
30-
*/
319
public class _399 {
3210

3311
public static class Solution1 {
3412
/**
3513
* Credit: https://discuss.leetcode.com/topic/59146/java-ac-solution-using-graph
36-
*
14+
* <p>
3715
* Image a/b = k as a link between node a and b, the weight from a to b is k, the reverse link
3816
* is 1/k. Query is to find a path between two nodes.
3917
*/
@@ -68,7 +46,7 @@ public double[] calcEquation(String[][] equations, double[] values, String[][] q
6846
}
6947

7048
private double dfs(String start, String end, Map<String, List<String>> pairs,
71-
Map<String, List<Double>> valuePairs, HashSet<String> set, double value) {
49+
Map<String, List<Double>> valuePairs, HashSet<String> set, double value) {
7250
if (set.contains(start)) {
7351
return 0.0;
7452
}

0 commit comments

Comments
 (0)