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

Function traversal

JavaScript/111-minimum-depth-of-binary-tree.js:33–56  ·  view source on GitHub ↗
(root, depth)

Source from the content-addressed store, hash-verified

31// traversal of the tree is recursive to ensure travel down
32// both the right and left children nodes
33var traversal = (root, depth) => {
34 let current = root;
35 let right;
36 let left;
37 if(!current) {
38 return null;
39 // this checks if the current node is a leaf node
40 } if (!current.right && !current.left) {
41 return depth;
42 }
43 right = traversal(current.right, depth+1)
44 left = traversal(current.left, depth+1)
45 if(!right) {
46 return left;
47 } else if(!left) {
48 return right;
49 } else {
50 if(right < left) {
51 return right
52 } else {
53 return left
54 }
55 }
56}

Callers 1

minDepthFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected