Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 646 Bytes

File metadata and controls

34 lines (24 loc) · 646 Bytes

Challenge Title : Tree Max

Whiteboard Process

Binary Tree

Whiteboard Link

Binar Tree


Solution

treeMax() {
    let maxValue = 0;

    let traverse = (node) => {
      if (!this.root) {
        return null;
      }
      if (node.value > maxValue) {
        maxValue = node.value;
      }
      if (node.left) traverse(node.left);
      if (node.right) traverse(node.right);
    };
    traverse(this.root);

    return maxValue;
  }