package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
1382. Balance a Binary Search Tree
Solution idea
构造BST
- Step 1: 中序遍历获取 BST 的有序结果
- Step 2: 然后用108. Convert Sorted Array to Binary Search Tree的解法代码,将这个有序数组转化成平衡 BST
Time complexity = $O(n) + O(\log n) = O(n)$