LeetCode Invert Binary Tree
来源:互联网 发布:js女装是什么牌子档次 编辑:程序博客网 时间:2024/05/16 05:54
# Definition for a binary tree node.class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = Noneclass Solution(object): def invertTree(self, root): """ :type root: TreeNode :rtype: TreeNode """ stack = [root] while stack: t= stack.pop() if t: t.left,t.right = t.right,t.left stack.append(t.left) stack.append(t.right) return rootclass Solution2(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 rootif __name__ == '__main__': root = TreeNode(1) a = TreeNode(2) b = TreeNode(3) root.left=a root.right=b Solution().invertTree(root) print root.left.val,root.right.val
0 0
- [leetcode] Invert Binary Tree
- [LeetCode]Invert Binary Tree
- leetcode:Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode | Invert Binary Tree
- leetcode--Invert Binary Tree
- [leetcode] Invert Binary Tree
- [LeetCode] Invert Binary Tree
- LeetCode Invert Binary Tree
- leetcode : Invert Binary Tree
- [LeetCode] Invert Binary Tree
- [Leetcode]Invert Binary Tree
- LeetCode: Invert Binary Tree
- LeetCode Invert Binary Tree
- leetcode: Invert Binary Tree
- LeetCode Invert Binary Tree
- LeetCode || Invert Binary Tree
- LeetCode:Invert Binary Tree
- 对Java的内存分配的简单了解(1)
- 一种批量删除数据的方法
- 网易17春招笔试题
- 计算几何学习笔记
- QTreeView冻结列(QTreeView第一列不随滑块移动)
- LeetCode Invert Binary Tree
- 使用md5在SQL中加密
- cocos2d-x 3.10 BabeLua 插件不能断点调试
- TCP通信的三次握手及四次挥手
- SyntaxError: Non-UTF-8 code but no encoding declared
- Java下利用Jackson进行JSON解析和序列化
- LeetCode Sum of Two Integers
- Python编程:从入门到实践读书笔记-5 if语句 & 6 字典
- 从Slice_Header学习H.264(三.1)--相关细节之 POC的计算