leetcode 226. Invert Binary Tree
来源:互联网 发布:ps4没有备份数据 编辑:程序博客网 时间:2024/06/07 13:34
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. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* invertTree(TreeNode* root) { if(root == nullptr) return root; if(root->left != nullptr|| root->right != nullptr) { TreeNode*temp ; temp = root ->left; root->left = root ->right; root->right = temp; invertTree(root->left); invertTree(root->right); } return root; }};
阅读全文
0 0
- 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
- LeetCode #226. Invert Binary Tree
- [LeetCode]226. Invert Binary Tree
- 226. Invert Binary Tree LeetCode
- 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
- 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
- android开发-IntentService的原理(非主线程创建Handler的情况)
- jq代码学习13---表单验证
- java图片颜色取反色,照片底片模式
- 数码管逐次加一同时流水灯
- Python yield 的理解
- leetcode 226. Invert Binary Tree
- 基于CENTOS6.5搭建Hadoop集群
- 数值计算方法(高斯消元以及LU分解)
- 二分搜索树(二)
- JAVA配置环境变量
- java并发中的ReentrantLock
- 进程间通信(2)-无名管道
- CS R26 C(双指针),D(观察,模拟),E(LIS经典 好题)
- 剑指offer——c++中,有哪4个与类型有关的关键字?它们各有的特点?应该在什么场合使用?