LeetCode 226----Invert Binary Tree
来源:互联网 发布:淘宝813是什么活动 编辑:程序博客网 时间:2024/04/29 22:21
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9to
4 / \ 7 2 / \ / \9 6 3 1二叉树反转,采用递归的方式。
- 输入结点为空时,返回为空;
- 将右子树反转,left指向右子树;将左子树反转,将right指向左子树。
/** * 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; TreeNode* p=root->left; root->left=invertTree(root->right); root->right=invertTree(p); return root; }};
0 0
- 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
- leetcode 226--Invert Binary Tree
- 【LEETCODE】226-Invert Binary Tree
- 论文研读《JOTS: Joint Online Tracking and Segmentation》
- 二分查找及其变形总结
- Flume学习6_flume配置文件
- Fiddler 4 中如何post数据
- 桌面图标删除不了
- LeetCode 226----Invert Binary Tree
- FilterInputStream的mark和resetf方法
- Spark jar not loaded. Offending class: javax/servlet/Servlet.class
- 作为团队Boss,如何处理PM与RD之间的矛盾?
- Monkey测试(二)
- iOS 延时的几种方法
- Wireshark抓取本机报文
- web集群之三 总结
- JSP中九大内置对象和四大作用域