Skip to content

Commit 9573563

Browse files
add 426
1 parent 69b5cb2 commit 9573563

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ _If you like this project, please leave me a star._ ★
10191019
| 432 | [All O`one Data Structure](https://leetcode.com/problems/all-oone-data-structure/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_432.java) | | Hard | Design
10201020
| 430 | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_430.java) | | Medium | LinkedList, DFS, Doubly-Linked List
10211021
| 429 | [N-ary Tree Level Order Traversal](https://leetcode.com/problems/n-ary-tree-level-order-traversal/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_429.java) | | Easy | BFS, Tree
1022+
| 426 | [Convert Binary Search Tree to Sorted Doubly Linked List](https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_426.java) | | Medium | DFS, BST, Recursion
10221023
| 425 | [Word Squares](https://leetcode.com/problems/word-squares/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_425.java) | | Hard | Trie, Backtracking, Recursion
10231024
| 424 | [Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_424.java) | | Medium | Sliding Window
10241025
| 423 | [Reconstruct Original Digits from English](https://leetcode.com/problems/reconstruct-original-digits-from-english/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_423.java) | | Medium | Math

Diff for: src/main/java/com/fishercoder/solutions/_426.java

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _426 {
4+
5+
public static class Solution1 {
6+
Node head;
7+
Node tail;
8+
9+
public Node treeToDoublyList(Node root) {
10+
if (root == null) {
11+
return null;
12+
}
13+
dfs(root);
14+
tail.right = head;
15+
head.left = tail;
16+
return head;
17+
}
18+
19+
private void dfs(Node node) {
20+
if (node == null) {
21+
return;
22+
}
23+
dfs(node.left);
24+
if (head == null) {
25+
head = node;
26+
}
27+
if (tail != null) {
28+
tail.right = node;
29+
node.left = tail;
30+
}
31+
tail = node;
32+
dfs(node.right);
33+
}
34+
}
35+
36+
private static class Node {
37+
public int val;
38+
public Node left;
39+
public Node right;
40+
41+
public Node() {
42+
}
43+
44+
public Node(int _val) {
45+
val = _val;
46+
}
47+
48+
public Node(int _val, Node _left, Node _right) {
49+
val = _val;
50+
left = _left;
51+
right = _right;
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)