LeetCode Algorithms #226 <Invert Binary Tree>
来源:互联网 发布:c 二维数组输出 编辑:程序博客网 时间:2024/06/05 06:48
invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9
to 4 / \ 7 2 / \ / \9 6 3 1
思路:
简单的递归调用,不知道Homebrew的作者为什么没做出来。
解:
<span style="font-size:14px;">/** * 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 == NULL) return NULL; invertTree(root->left); invertTree(root->right); TreeNode *tempNode = root->left; root->left = root->right; root->right = tempNode; return root; }};</span>
0 0
- LeetCode Algorithms #226 <Invert Binary Tree>
- LeetCode Algorithms 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
- LeetCode 226Invert 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
- linux常用命令总结
- 编写一个C#程序,要求定义一个行数和列数相等的二维数组, 并执行初始化,然后计算并输出数组两条对角线上的元素之和。
- javaweb 三大组件之Severlet
- 【欧拉函数模板】
- oracle超级用户connection
- LeetCode Algorithms #226 <Invert Binary Tree>
- Android应用开发性能优化完全分析
- Spring + hibernate5 搭建web配置事务处理
- ios网络请求报错:the App Transport Security policy requires the use of a secure connection
- 面试笔试题知识点回顾
- AppleWatch真机调试问题:App Transport Security has blocked a cleartext HTTP(http://)resource load since...
- iOS9种关于App Transport Security详细说明
- 百度地图API学习总结
- 物理渲染-基于物理的光照模型