c语言一维数组怎么快速排列
303
2022-08-29
LeetCode-897. Increasing Order Search Tree
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 / / \ 1 7 9Output: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9] 1 \ 2 \ 3 \ 4 \ 5 \ 6 \ 7 \ 8 \ 9
Note:
The number of nodes in the given tree will be between 1 and 100.Each node will have a unique integer value from 0 to 1000.
题解:好坑啊。。。一直以为输入是二叉排序树。。。题目也不讲清楚
dfs疯狂WA
class Solution {public: TreeNode* increasingBST(TreeNode* root) { TreeNode *p = root; vector
中序遍历ok了
class Solution {public: TreeNode* increasingBST(TreeNode* root) { TreeNode *p = root; vector
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~