LeetCode OJ
Problems
Pick One!
Submissions
Sign up
Sign in
Convert Sorted Array to Binary Search Tree
AC Rate: 1517/4549
My Submissions
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
C++
Java
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: TreeNode *sortedArrayToBST(vector<int> &num) { // Note: The Solution object is instantiated only once and is reused by each test case. } };
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public TreeNode sortedArrayToBST(int[] num) { // Note: The Solution object is instantiated only once and is reused by each test case. } }
Submit Solution
You have not signed in, cannot submit your code.
Submit failed, try again please.
You have attempted to resubmit too soon. Please resubmit in a moment.
Send Feedback