MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / preorder

Method preorder

Java/binary-tree-preorder-traversal.java:21–36  ·  view source on GitHub ↗
(TreeNode root, List<Integer> ls)

Source from the content-addressed store, hash-verified

19 return ls;
20 }
21 public void preorder(TreeNode root, List<Integer> ls){
22 /* Preorder traversal is visiting : root then left subtree then right subtree */
23
24 /* if node is null, then return back to the caller function */
25 if(root==null)
26 return;
27
28 /* Add the current node's value to the list */
29 ls.add(root.val);
30
31 /* Recurse for left subtree */
32 preorder(root.left, ls);
33
34 /* Recurse for right subtree */
35 preorder(root.right, ls);
36 }
37}

Callers 1

preorderTraversalMethod · 0.95

Calls 1

addMethod · 0.45

Tested by

no test coverage detected