We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 494c2f0 commit 1fd8f2bCopy full SHA for 1fd8f2b
scripts/algorithms/B/Balance a Binary Search Tree/Balance a Binary Search Tree.cpp
@@ -1,3 +1,4 @@
1
+// Runtime: 305 ms (Top 25.60%) | Memory: 63.3 MB (Top 34.89%)
2
class Solution {
3
public:
4
vector<int> nums ;
@@ -8,20 +9,20 @@ class Solution {
8
9
traverse(root->right) ;
10
return ;
11
}
-
12
+
13
TreeNode * makeTree(int s , int e){
14
if(s > e) return nullptr ;
15
int m = (s + e) / 2 ;
16
TreeNode * root = new TreeNode(nums[m]) ;
17
18
root->left = makeTree(s,m - 1) ;
19
root->right = makeTree(m + 1,e) ;
20
21
return root ;
22
23
24
TreeNode* balanceBST(TreeNode* root) {
25
traverse(root) ;
26
return makeTree(0,size(nums) - 1) ;
27
-};
28
+};
0 commit comments