垃圾翻译,毁我青春
原题为:Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only 1 right child.
居然给翻译成了:给定一个二叉树,重新排列树,使树中的最小值现在是树的根结点,并且每个结点没有左子结点,只有一个右子结点。
至少in-order你给翻译出来吧,以后放弃LeetCode-CN平台,转战LeetCode
在这个这么简单的题目上浪费了二十分钟真是不值得,包括五分钟写好,十五分钟冥思苦想就是不知道哪里错了
/**
* 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:
void preTrav(TreeNode* cur,vector<int>& inorder){
if(cur==NULL)return;
preTrav(cur->left,inorder);
inorder.push_back(cur->val);
preTrav(cur->right,inorder);
}
TreeNode* increasingBST(TreeNode* root) {
vector<int> inorder;
preTrav(root,inorder);
int n=inorder.size();
if(n==0)return root;
root=new TreeNode(inorder[0]);
TreeNode* cur=root;
for(int i=1;i<n;i++){
cur->right=new TreeNode(inorder[i]);
cur=cur->right;
}
return root;
}
};