LeetCode 426. Convert Binary Search Tree to Sorted Doubly Linked List - 链表(Linked List)系列题24

题目要求把一棵二叉搜索树转换成一个循环双向链表。具体要求是一个节点的左指针left指向其前继(predecessor),右指针right指向后继(successor)。最后头节点的left指向尾节点,尾节点的right指向头节点。如果熟悉前继和后继的概念就会知道最后链表是排好序递增的,其实就是二叉搜索树的中序遍历的顺序。很显然又是可以用递归法或迭代法。
摘要由CSDN通过智能技术生成

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:

Input: root = [4,2,5,1,3]


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值