MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / dfs

Method dfs

java/0606-construct-string-from-binary-tree.java:21–32  ·  view source on GitHub ↗
(TreeNode root, StringBuilder res)

Source from the content-addressed store, hash-verified

19 return res.toString().substring(1, res.length()-1);
20 }
21 private void dfs(TreeNode root, StringBuilder res){
22 if(root == null)
23 return;
24
25 res.append("(");
26 res.append(root.val);
27 if(root.left == null && root.right != null)
28 res.append("()");
29 dfs(root.left, res);
30 dfs(root.right, res);
31 res.append(")");
32 }
33}

Callers 1

tree2strMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected