LC.226.Invert Binary Tree

Posted davidnyc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LC.226.Invert Binary Tree相关的知识,希望对你有一定的参考价值。

https://leetcode.com/problems/invert-binary-tree/description/
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
time: o(n) : n nodes
space: o(n): worst case linkedlist and n calling stack


1 public TreeNode invertTree(TreeNode root) {
2         if (root == null) return null ;
3         TreeNode left = invertTree(root.left) ;
4         TreeNode right = invertTree(root.right) ;
5         root.right = left ;
6         root.left = right ;
7         return root ;
8     }

 

以上是关于LC.226.Invert Binary Tree的主要内容,如果未能解决你的问题,请参考以下文章

[Leetcode] Binary tree-- 606. Construct String from Binary Tree

[Leetcode] Binary search tree --Binary Search Tree Iterator

[数据结构]Binary_tree | Binary_search_tree | avl_tree

[Lintcode]95. Validate Binary Search Tree/[Leetcode]98. Validate Binary Search Tree

[Leetcode] Binary tree -- 501. Find Mode in Binary Search Tree

[LeetCode] 173. Binary Search Tree Iterator_Medium_tag: Binary Search Tree