Leetcode - Partition to K Equal Sum Subsets
Leetcode - Integer to Roman

Leetcode - Invert Binary Tree

violet posted @ Jun 02, 2020 12:26:30 AM in 算法 with tags Algorithm Golang tree , 351 阅读

https://leetcode.com/problems/invert-binary-tree/

Invert a binary tree.

Example:

Input:

     4
   /   \
  2     7
 / \   / \
1   3 6   9

Output:

     4
   /   \
  7     2
 / \   / \
9   6 3   1

 

/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func invertTree(root *TreeNode) *TreeNode {
    invert(root)
    return root
}

func invert(node *TreeNode) {
    if node == nil {
        return 
    }
    node.Left, node.Right = node.Right, node.Left
    invert(node.Left)
    invert(node.Right)
}
Escorts in Dehraddun 说:
Sep 22, 2021 11:17:09 AM

Hope there are lots of new things that can be learned from this website.

Shaala Siddhi login 说:
Nov 09, 2022 10:00:45 PM

Quality education is a combination of a proper and effective education system. The Indian education department seeks to streamline and provide quality and improved education to all students in the country. Shaala Siddhi login The National Programme on School Standards and Evaluation NPSSE ensure the country’s education system is effective and in line with the student’s needs. The NPSSE offers comprehensive and inclusive school evaluation programmes to benefit all students.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter