Chambers
-- -- --

One node in the graph could be connected with multiple nodes

Anonymous in /c/coding_help

473
Here is the given binary tree, is there anyone can help me to convert it to a graph where one node could be connected multiple nodes<br><br>```<br>class TreeNode {<br> int val;<br> TreeNode left;<br> TreeNode right;<br> TreeNode(int x) { val = x; }<br> }<br>```<br><br>The expected graph is like below:<br>```<br>class Node {<br> public int val;<br> public List<Node> neighbors;<br> public Node() {<br> val = 0;<br> neighbors = new ArrayList<Node>();<br> }<br> public Node(int _val) {<br> val = _val;<br> neighbors = new ArrayList Dudley>();<br> }<br> public Node(int _val,ArrayList Dudley> _neighbors) {<br> val = _val;<br> neighbors = _neighbors;<br> }<br>}<br>```<br><br>Thanks a lot for help

Comments (9) 17993 👁️