226. Invert Binary Tree
来源:互联网 发布:信捷xc系列编程手册 编辑:程序博客网 时间:2024/06/05 14:58
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9to
4 / \ 7 2 / \ / \9 6 3 1Trivia:
This problem was inspired by this original tweet by Max Howell:
思路很简单,【递归地】交换节点的左右子树。
public TreeNode invertTree(TreeNode root){if(root!=null)change(root);return root;}public void change(TreeNode t){if(t.left!=null)change(t.left);if(t.right!=null)change(t.right);TreeNode temp=t.right;t.right=t.left;t.left=temp;}
0 0
- 226.Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- C语言基础 输入三角形的三条边,求其面积
- C++ - 计蒜客 - 大钉骑马走江湖(bfs)
- 1 内核重要性
- spi驱动
- 古人的礼仪、刑罚
- 226. Invert Binary Tree
- 【matlab】在程序运行结果中保存数据到txt文档
- i2c驱动
- http协议_思维导图总结2
- ADO.NET中的Connection对象
- 自适应中值滤波RAMF
- qwdqwdqwdqwqwd
- 队列
- 225. Implement Stack using Queues