GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • LeetCodeJavascript.com
  • Star on GitHub

This view

  • Original page
  • New address

GeezerVison is showing leetcodejavascript.com — #226 - Invert Binary Tree - LeetCode JavaScript Solutions

Back to all solutions

#226 - Invert Binary Tree

Easy • View on LeetCode • View on GitHub
Depth-First Search Tree Breadth-First Search Binary Tree

Problem Description

Invert a binary tree.

Solution

/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} node
 * @return {TreeNode}
 */
var invertTree = function(node) {
  if (node) [node.left, node.right] = [invertTree(node.right), invertTree(node.left)];
  return node;
};
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.