Chinaunix首页 | 论坛 | 博客
  • 博客访问: 40259
  • 博文数量: 37
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 372
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-12 23:27
文章分类

全部博文(37)

文章存档

2014年(5)

2013年(32)

我的朋友

分类: C/C++

2013-12-04 18:03:05


点击(此处)折叠或打开

  1. /**
  2.  * Definition for binary tree
  3.  * struct TreeNode {
  4.  * int val;
  5.  * TreeNode *left;
  6.  * TreeNode *right;
  7.  * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  8.  * };
  9.  */
  10. class Solution {
  11. public:
  12.     void flatten(TreeNode *root) {
  13.         // Note: The Solution object is instantiated only once and is reused by each test case.
  14.         if(NULL==root) return;
  15.         flatten(root->left);
  16.         flatten(root->right);
  17.         if(NULL==root->left) return;
  18.         TreeNode *tmp=root->left;
  19.         while(tmp->right) tmp=tmp->right;
  20.         tmp->right=root->right;
  21.         root->right=root->left;
  22.         root->left=NULL;
  23.     }
  24. };

阅读(92) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~