Answers for "invert binary tree javascript"

1

invert binary tree javascript

function invertTree(head) {
  if (head) {
    var temp = head.left;
    head.left = head.right;
    head.right = temp;

    invertTree(head.left);
    invertTree(head.right);
  }

  return head;
}
Posted by: Guest on May-25-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language