LeeCode-Invert Binary Tree
2015-07-20 09:15
471 查看
Invert a binary tree.
to
4 / \ 2 7 / \ / \ 1 3 6 9
to
4 / \ 7 2 / \ / \ 9 6 3 1
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public TreeNode invertTree(TreeNode root) { if(root!=null) { TreeNode temp = root.left; root.left = root.right; root.right = temp; invertTree(root.left); invertTree(root.right); return root; } return null; } }
相关文章推荐
- oracle connect by用法
- iOS开发 偷懒小技巧---自定义XCode代码片段
- 折价买分级基金的教程
- Struts2 国际化
- 开始刷leetcode day72: Kth Smallest Element in a BST
- Objective-C设计模式——抽象工厂模式Abstract Factory(对象创建)
- The import java.util cannot be resolved
- Vim技巧之四大模式_普通模式
- 动画特效六:三维过度
- LeeCode-Contains Duplicate
- Android 代码混淆打包
- iOS开发zhiATM机的设计与实现
- Python绘图基础
- 据序和中序序列或者也许为了一个二进制序列,恢复二进制和打印图像(c语言)
- 计蒜客-----泥塑课
- LeeCode-Linked List Cycle
- java synchronized用法
- 初识命令行参数(以my_chmod为例)
- eclipse解决editor does not contain a main type的方法
- Vim技巧之重复