Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 660 Bytes

226.md

File metadata and controls

28 lines (23 loc) · 660 Bytes

Leetcode 226. 翻转二叉树

226. 翻转二叉树

/**

  • Definition for a binary tree node.

  • function TreeNode(val, left, right) {

  • this.val = (val===undefined ? 0 : val)
    
  • this.left = (left===undefined ? null : left)
    
  • this.right = (right===undefined ? null : right)
    
  • } / /*

  • @param {TreeNode} root

  • @return {TreeNode} */ var invertTree = function(root) { if(root == null){ return root; }

    let left = invertTree(root.left); let right = invertTree(root.right);

    [root.left,root.right] = [root.right,root.left];

    return root; };