leetcode897】的更多相关文章

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. Example 1: Input: [5,3,6,2,4,null,8,1,null,null,null,7,9] 5 / \ 3 6 / \ \ 2 4 8  …
这道题用C++来写,在本地执行正常,但是使用OJ判断输出结果是空,暂时不清楚原因.代码如下: class Solution { public: vector<int> V; //中序遍历 void MidTree(TreeNode node) { if (&node != NULL) { if (node.left != NULL) { MidTree(*node.left); } V.push_back(node.val); if (node.right != NULL) { Mid…
题目 法一.自己 1 class Solution { 2 public: 3 vector<int>res; 4 TreeNode* increasingBST(TreeNode* root) { 5 dfs(root); 6 TreeNode* p = new TreeNode(0); 7 TreeNode *cur = p; 8 for(int i =0;i <res.size();i++){ 9 cur->val = res[i]; 10 //cur->right =…
897. 递增顺序查找树 897. Increasing Order Search Tree 题目描述 给定一个树,按中序遍历重新排列树,使树中最左边的结点现在是树的根,并且每个结点没有左子结点,只有一个右子结点. LeetCode897. Increasing Order Search Tree 示例: 输入: [5,3,6,2,4,null,8,1,null,null,null,7,9] ``` 5 / \ 3 6 / \ \ 2 4 8 / / \ 1 7 9 ``` 输出: [1,nul…