109*. Convert Sorted List to Binary Search Tree
题目
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
Example:
1 | Given the sorted linked list: [-10,-3,0,5,9], |
大意
答案
1 | class Solution { |
思路
利用快慢指针找到中间节点,作为根节点,然后左子树即为左边链表部分,右子树即为右边链表部分,递归进行即可。
Author: corn1ng
Link: https://corn1ng.github.io/2018/01/31/算法/leetcode109/
License: 知识共享署名-非商业性使用 4.0 国际许可协议