| 9 | */ |
| 10 | |
| 11 | fun graphDeepCopy(node: GraphNode?): GraphNode? { |
| 12 | if (node == null) { |
| 13 | return null |
| 14 | } |
| 15 | return dfs(node, mutableMapOf()) |
| 16 | } |
| 17 | |
| 18 | fun dfs(node: GraphNode, cloneMap: MutableMap<GraphNode, GraphNode>): GraphNode { |
| 19 | // If this node was already cloned, then return this previously |