题解 | #二叉搜索树与双向链表#
二叉搜索树与双向链表
https://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5
import java.util.*; /** public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { private TreeNode head = null; private TreeNode pre = null; public TreeNode Convert(TreeNode pRootOfTree) { if (pRootOfTree == null) { return pRootOfTree; } Convert(pRootOfTree.left); if (pre == null) { head = pRootOfTree; pre = pRootOfTree; } else { pre.right = pRootOfTree; pRootOfTree.left = pre; pre = pRootOfTree; } Convert(pRootOfTree.right); return head; } }