226. Invert Binary Tree Difficult: Easy
来源:互联网 发布:淘宝换货售后卡怎么写 编辑:程序博客网 时间:2024/04/25 09:32
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9
to
4 / \ 7 2 / \ / \9 6 3 1
算法分析:可以用层序遍历的方法交换左右子树,也可以直接递归。
C语言版
struct TreeNode* invertTree(struct TreeNode* root) { if(root) { struct TreeNode *temp = root->right; root->right = invertTree(root->left); root->left = invertTree(temp); } return root;}
Python版
class Solution(object): def invertTree(self, root): """ :type root: TreeNode :rtype: TreeNode """ if root: root.left, root.right = self.invertTree(root.right), self.invertTree(root.left) return root
阅读全文
0 0
- 226. Invert Binary Tree Difficult: Easy
- 226. Invert Binary Tree (Easy)
- 【leetcode】【Easy】【226. Invert Binary Tree】【tree】
- Invert Binary Tree(easy)
- 226. Invert Binary Tree [easy] (Python)
- Easy-题目4:226. Invert Binary Tree
- Leetcode 226. Invert Binary Tree (Easy) (cpp)
- LeetCode 226. Invert Binary Tree (Easy)
- Leet Code OJ 226. Invert Binary Tree [Difficulty: Easy]
- 226.leetcode Invert Binary Tree(easy)[二叉树 递归]
- [Leetcode 226, Easy] Invert Binary Tree
- <LeetCode><Easy>226Invert a binary tree
- Easy 226题 Invert Binary Tree
- LeetCode #226 - Invert Binary Tree - Easy
- 【Leetcode-easy-226】Invert Binary Tree
- 226.Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 设计模式之策略模式
- 聊聊PhoneWindow,getDecorView(),setContentView
- 14.读书笔记收获不止Oracle之 索引
- 关于反码,byte最大值127,最小值-128的由来缘由以及书本上从未讲解过的反码补码功能作用
- USB接口的功能和区分全解析
- 226. Invert Binary Tree Difficult: Easy
- pos1007
- 静态链接库(.lib)和动态链接库(.dll)的区别和使用
- 15.读书笔记收获不止Oracle之 索引高度
- 关系密切的设计模式(一)
- 16.读书笔记收获不止Oracle之 分区索引
- python学习笔记
- (转)金融从业人员的核心竞争力在哪里?
- 17.读书笔记收获不止Oracle之 索引存储列值