426 Convert Binary Search Tree to Sorted Doubly Linked List
1. Question
Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers as synonymous to the previous and next pointers in a doubly-linked list.
2. Implementation
思路: 通过Inorder traversal遍历Binary Search Tree, 同时维护preNode, 将preNode 和 当前的node像double linked list那样连起来。最后再将double linked list的head和tail连起来即可
3. Time & Space Complexity
时间复杂度O(n), 空间复杂度O(h), 递归深度是树的高度
Last updated
Was this helpful?