mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 07:33:45 +00:00
Update 36. 二叉搜索树与双向链表.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
+11
-5
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user