Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript invert binary tree

// invert binary  tree using recursive function

function invertTree(node) {
  if (node && node.left) {
      let left = node.left;
      node.left = node.right;
      node.right = left;
      invertTree(node.right);
      invertTree(node.left);
  }
  return node;
}
 
PREVIOUS NEXT
Tagged: #JavaScript #invert #binary #tree
ADD COMMENT
Topic
Name
5+9 =