每日一题 LeetCode 897. 递增顺序搜索树 java题解
作者:互联网
题目
https://leetcode-cn.com/problems/increasing-order-search-tree/
代码
class Solution {
TreeNode pre;
public TreeNode increasingBST(TreeNode root) {
TreeNode tmp=new TreeNode(-1);
pre=tmp;
dfs(root);
return tmp.right;
}
public void dfs(TreeNode root){
if(root==null){
return;
}
dfs(root.left);
pre.right=root;
root.left=null;
pre=root;
dfs(root.right);
}
}
复杂度
标签:pre,tmp,right,TreeNode,897,题解,dfs,java,root 来源: https://blog.csdn.net/weixin_42970433/article/details/116138343