Leetcode 399. Evaluate Division
- Type: Graph (dfs)
- Approach:
- We know the equations and corresponding values so that we can build a directed graph to store the division value of two number.
- As for a given unknown equation, we can use dfs to search the equation exists or not.
- The dfs is bottom-up method and if the division value of two number exists, we return the value, otherwise, we return -1.
- Complexity:
- Time: O(V+E)
- Space: O(n)