LC: 426. Convert Binary Search Tree to Sorted Doubly Linked List
https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/
Convert a Binary Search Tree to a sorted Circular Doubly-Linked List in place.
You can think of the left and right pointers as synonymous to the predecessor and successor pointers in a doubly-linked list. For a circular doubly linked list, the predecessor of the first element is the last element, and the successor of the last element is the first element.
We want to do the transformation in place. After the transformation, the left pointer of the tree node should point to its predecessor, and the right pointer should point to its successor. You should return the pointer to the smallest element of the linked list.
Example 1:

Example 2:
Example 3:
Example 4:
Constraints:
The number of nodes in the tree is in the range
[0, 2000].-1000 <= Node.val <= 1000All the values of the tree are unique.
The Essence:
Die linke und der rechte Knoten eines Elterknotens können als Vorgänger und Nachfolger interpretiert werden. Der linkeste Knoten entspricht dem Kopfknoten der Liste. Ein Vorgänger-Knoten entspricht dem Knoten mit höchstem Wert in dem linken Teilbaum und ein Nachfolger entspricht dem Knoten mit niedrigsten Wert in dem rechten Teilbaum.
Details:
Da man eine “circular” Liste braucht, muss man dieser linkeste Knoten zu einem Sentinel-Knoten verbinden, um am Ende den Linkesten mit dem rechtesten Knoten zu verbinden.
Solution:
Default Code:
Last updated