Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

binary tree

// find maixmum node in binary tree 
const Max = (root) => {
  let max = -Infinity;
  let stack = [root];

  while (stack.length) {
    let current = stack.pop();
    if (current.data > max) {
      max = current.data;
    }
    if (current.left !== null) stack.push(current.left);
    if (current.right !== null) stack.push(current.right);
  }

  return max;
};
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #binary #tree
ADD COMMENT
Topic
Name
1+9 =