diff --git a/notes/36. 二叉搜索树与双向链表.md b/notes/36. 二叉搜索树与双向链表.md index 58b61faf..7c474b6f 100644 --- a/notes/36. 二叉搜索树与双向链表.md +++ b/notes/36. 二叉搜索树与双向链表.md @@ -1,6 +1,6 @@ # 36. 二叉搜索树与双向链表 -[NowCoder](https://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5?tpId=13&tqId=11179&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github) +[Leetcode](https://leetcode.cn/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/) ## 题目描述 @@ -11,15 +11,21 @@ ## 解题思路 ```java -private TreeNode pre = null; -private TreeNode head = null; +private Node pre = null; +private Node head = null; -public TreeNode Convert(TreeNode root) { +public Node treeToDoublyList(Node root) { + if (root == null) + return null; + head = null; + pre = null; inOrder(root); + head.left = pre; + pre.right = head; return head; } -private void inOrder(TreeNode node) { +private void inOrder(Node node) { if (node == null) return; inOrder(node.left);