Leetcode - Invert Binary Tree
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /** * 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) } |
4 年前
Hope there are lots of new things that can be learned from this website.
2 年前
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.