翻转二叉树
来源:互联网 发布:提醒事项软件 编辑:程序博客网 时间:2024/05/29 23:23
翻转一棵二叉树
样例
1 1 / \ / \2 3 => 3 2 / \ 4 4
解题思路:dfs进行遍历,并且建立一个临时指针,每次对左右结点进行地址调换即可。
class Solution {public: /** * @param root: a TreeNode, the root of the binary tree * @return: nothing */ TreeNode *tem; void invertBinaryTree(TreeNode *root) { // write your code here if(root==NULL)return; tem=root->right; root->right=root->left; root->left=tem; invertBinaryTree(root->left); invertBinaryTree(root->right); }
0 0
- C++二叉树翻转
- 翻转二叉树
- 翻转二叉树
- 题目:翻转二叉树
- LintCode 翻转二叉树
- LinkCode-翻转二叉树
- 翻转二叉树
- 翻转二叉树
- 翻转二叉树
- LintCode_175_翻转二叉树
- 二叉树翻转
- lintcode ----翻转二叉树
- lintcode,翻转二叉树
- 翻转二叉树
- 翻转二叉树
- 翻转二叉树
- 翻转二叉树
- LintCode-翻转二叉树
- 程序猿技能表
- cuda sm执行block的数量
- Cannot read property 'nodeName' of null
- CK2
- Android自定义View之微信雷达
- 翻转二叉树
- 关于EL表达式中requestScope和param区别
- 逻辑斯谛回归学习总结
- 03.js中apply方法的使用
- [Java 安全]消息摘要与数字签名
- 类的构造函数,析构函数与赋值函数
- iCheck的全选js
- 对象模型
- java中的各种缩写