Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. If you have not checked out my previous post: Convert Sorted Array to Balanced Binary Search Tree (BST) , you should check it out now as this solution is built upon the previous solution. Things get a little more complicated when you have a singly linked list instead of an array. Please note that in linked list, you no longer have random access to an element in O(1) time. Singly-linked lists contain nodes which have a data field as well as a next field,
Read full article from Convert Sorted List to Balanced Binary Search Tree (BST) | LeetCode
No comments:
Post a Comment