Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
有序的數(shù)組轉(zhuǎn)換成高度平衡的二叉排序樹。
代碼:
參考代碼
中間的節(jié)點作為根節(jié)點,左邊的節(jié)點是left和mid-1的中間的節(jié)點,右邊的節(jié)點類似。
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
有序的數(shù)組轉(zhuǎn)換成高度平衡的二叉排序樹。
中間的節(jié)點作為根節(jié)點,左邊的節(jié)點是left和mid-1的中間的節(jié)點,右邊的節(jié)點類似。