Simple C solution 4 ms

  • 0
    struct TreeNode *createTree(int a[],int low,int high)
        if(low > high)
            return NULL;
        int mid = low + (high-low)/2;
        struct TreeNode *root = (struct TreeNode *)malloc(sizeof(struct TreeNode));
        root->val = a[mid];
        root->left = createTree(a,low,mid-1);
        root->right = createTree(a,mid+1,high);
        return root;
    struct TreeNode* sortedArrayToBST(int* nums, int numsSize) {
        return createTree(nums,0,numsSize-1);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.