Invert Binary Tree
2015-10-20 14:57
218 查看
https://leetcode.com/problems/invert-binary-tree/
Invert a binary tree.4 / \ 2 7 / \ / \ 1 3 6 9
to
4 / \ 7 2 / \ / \ 9 6 3 1 直接用递归
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def invertTree(self, root): """ :type root: TreeNode :rtype: TreeNode """ if root: root.left,root.right = root.right,root.left self.invertTree(root.left) self.invertTree(root.right) return root
相关文章推荐
- prototypejs库Function#wrap()的使用和源码解析
- 静态页面之间传递参数
- 巧用Procexp找出弹窗广告真凶
- iOS: SegmentControl 实现页面切换的四种方法
- Android Drawable 那些不为人知的高效用法
- 真机测试出现的小问题
- groovy 变量作用域
- 第二章作业
- 加JENKINS的SLAVE节点(LINUX)要注意的事项
- 复用代码
- 人人必知的10个 jQuery 小技巧
- 怎么在spring官网下载jar包问题
- Android 相对布局中的 代码中修改属性与布局文件的设置不同的解决方法
- tcmallo
- ear 与war包结构的区别
- 软件架构师之AOP
- oracle序列的两个参数:nextval和currval简介
- 我在去哪儿干了些什么,3个月业绩400%提升 (一)完结
- 恢复平衡0x8b,0xff,0x55,0x8b,0xec
- 调研内容(算法相关--GDA,GMM)