My Blog List

[Leetcode Solution] Convert Sorted List to Binary Search Tree

Analysis

  • Idea by using recursion.
  • For converting a sorted list to binary search tree, firstly find the middle item in the list. 
  • Then recursively convert the first half list and second half list to two binary search tree separately. 
  • Finally create a new node with value of the middle item and each child pointer pointing to the two binary search tree built recursively before.

Note


Code


No comments:

Post a Comment

Enter you comment