lintcode翻转二叉树
2017-11-02 23:41
316 查看
翻转二叉树
描述笔记
数据
评测
总耗时: 254 ms
100% 数据通过测试.
还没解决的相关题目
26
%389. 判断数独是否合法容易20
%248. 统计比给定整数小的数的个数中等19
%249. 统计前面比自己小的数的个数困难14
%131. 大楼轮廓超难26
%370. 将表达式转换为逆波兰表达式困难
太牛了,把AC的喜悦分享给你的朋友吧!
解析:这道题的树并不是二叉查找树,所以对每个结点的左右结点交换即可。
/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/*
* @param root: a TreeNode, the root of the binary tree
* @return: nothing
*/
void invertBinaryTree(TreeNode * root) {
// write your code here
if(root==NULL)
return ;
invertBinaryTree(root->left);//后续遍历,先对左右结点操作
invertBinaryTree(root->right);
TreeNode *tmp;
tmp=root->left;
root->left=root->right;
root->right=tmp;
}
};
相关文章推荐
- LintCode(Flatten Binary Tree to Linked List)翻转二叉树为链表 的变体
- lintcode,翻转二叉树
- 算法题:lintcode#175 翻转二叉树(java)
- LintCode - 175.翻转二叉树
- lintcode——翻转二叉树
- LintCode -- 二叉树的中序遍历
- lintcode,二叉树的序列化和反序列化
- lintcode——二叉树的最小深度
- LintCode2016年8月22日算法比赛----克隆二叉树
- lintcode binary-tree-paths 二叉树的所有路径
- lintcode minimum-depth-of-binary-tree 二叉树最小深度
- Lintcode 二叉树的层次遍历
- 二叉树专题-lintcode非递归遍历与总结
- LintCode 35 翻转链表
- Lintcode---二叉树的最小深度
- LintCode之53 翻转字符串
- lintcode--翻转字符串
- lintcode&九章算法——No.97 二叉树的最大深度 ? 待解决
- Lintcode:二叉树的最大节点
- Lintcode翻转链表