226 Invert Binary Tree
来源:互联网 发布:什么是谷歌seo 编辑:程序博客网 时间:2024/04/30 00:38
/**
* 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) return null;
TreeNode left = root.left;
TreeNode right = root.right;
TreeNode tl = invertTree(left);
TreeNode tr = invertTree(right);
root.left = tr;
root.right = tl;
return root;
}
}
* 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) return null;
TreeNode left = root.left;
TreeNode right = root.right;
TreeNode tl = invertTree(left);
TreeNode tr = invertTree(right);
root.left = tr;
root.right = tl;
return root;
}
}
0 0
- 226Invert Binary Tree
- 226Invert 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
- 226Invert Binary Tree
- [226] Invert Binary Tree
- Leetcode[226]-Invert Binary Tree
- LeetCode 226 Invert Binary Tree
- Invert Binary Tree - LeetCode 226
- leetcode[226]:Invert Binary Tree
- leetcode 226: Invert Binary Tree
- Leetcode 226 Invert Binary Tree
- leetcode-226-Invert Binary Tree
- leetcode 226 :Invert Binary Tree
- codevs1059
- 黑马程序员--IO流
- hihoCoder - 1181 - 欧拉路·二 (Fleury算法求欧拉路径)
- Andorid Volley网络请求详解
- 如何安装Matlab版libsvm
- 226 Invert Binary Tree
- root用户不能修改iptables
- nunit的用法
- bat文件
- 关于 telnet 在windows 中的乱码问题
- 【Linux】linux常用基本命令
- hihoCoder - 1082 - 然而沼跃鱼早就看穿了一切(字符串处理)
- 网站日志挖掘介绍:目的、搜集方式、流程等
- CMFCShellTreeCtrl控件的效率改进