Why WA... Input: [0] Output: {} Expected: {0} HELP


  • 0
    P
    class Solution {
    public:
        TreeNode *sortedArrayToBST(vector<int> &num) {
           if(num.size() == 0) return NULL;
            TreeNode *root = NULL;
            next(0,num.size()-1,root,num);
            return root;
        }
        
           void next(int left,int right,TreeNode *tmp,vector<int> &vect)
        {
            
            tmp = new TreeNode(vect[(left+right)/2]);
            if(left == right)
                return;
            next(left,(left+right)/2,tmp->left,vect);
            next((left+right)/2+1,right,tmp->right,vect);
        }
    };

Log in to reply
 

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