Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
}
Comment

invert binary tree js

function invertTree(node) {
  if(!node) return;
  [node.left, node.right] = [node.right, node.left];
  invertTree(node.left);
  invertTree(node.right);
  return node;
}
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: nextjs change port 
Javascript :: find all checkbox inside div jquery 
Javascript :: js add more text to element 
Javascript :: how to set html label value in jquery 
Javascript :: Calling MVC controller from Javascript ajax 
Javascript :: css and js on flask 
Javascript :: javascript assign 
Javascript :: convert iso string to datetime javascript 
Javascript :: access to static file nodejs 
Javascript :: placeholder javascript 
Javascript :: last week date js 
Javascript :: mongoose get raw 
Javascript :: Checking Empty JS Object 
Javascript :: jquery select element with two classes 
Javascript :: angular disabled condition based 
Javascript :: js check link if exists 
Javascript :: get form data in react 
Javascript :: fetching foreign key data in sequelize 
Javascript :: mock a function jest react 
Javascript :: javascript remove underscore and capitalize 
Javascript :: select all elements javascript 
Javascript :: windows terminal vai kill all node js port 
Javascript :: Factorial multiplication in javascript 
Javascript :: array to excel javascript 
Javascript :: js string to regex 
Javascript :: how to tell the javascript to wait until the site loads in the html 
Javascript :: javascript get image width and height 
Javascript :: JavaScript HTML DOM - Changing CSS 
Javascript :: react forwardref 
Javascript :: how to find and remove object from array in javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =