LeetCode 226 Invert Binary Tree
来源:互联网 发布:qq五子棋游戏的源码 编辑:程序博客网 时间:2024/06/10 05:35
大意是,给一个二叉树,要求把二叉树镜像翻转,解决思路是递归反转,对于每一个节点,分别对换它的左节点和右节点,之后根据有无子节点的情况递归进行操作。
题目链接
代码如下
class Solution {public: void dfs(TreeNode* node) { swap(node->left, node->right); if (node->left) { if (node->right) { dfs(node->left); dfs(node->right); } else { dfs(node->left); } } else { if (node->right) { dfs(node->right); } else { return; } } } TreeNode* invertTree(TreeNode* root) { if (root != NULL) { dfs(root); } 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
- item1.xml(zhou3)
- 水题 第八站 HDU Train problem II
- item2.xml(zhou3)
- React+webpack 的开发环境配置步骤(一)
- oracle 11.2 rac主机不更换,迁移到新存储
- LeetCode 226 Invert Binary Tree
- 数组中有一个数字出现的次数超过了数组长度的一半,找出这个数
- 大三仍是Linux系统小白的我给大家讲讲学习历程
- POJ 1410 Intersection [线段相交+点在多边形内]
- 内存对齐和位域
- 模板总结
- 快速幂取模
- linux编程之stat函数
- 《神女峰》 舒婷