Output is same as expected but still showing wrong answer..!! any idea??


  • 0
    R
    class Solution {
    public:
        void inorder(TreeNode*root, int *x, int k,bool flag){
            static int i=0;
            if(root==NULL)
                return;
            inorder(root->left,x,k,flag);
            i++;
            if(i==k){
                *x=root->val;
                flag=true;    
            }
            if(!flag)
                inorder(root->right,x,k,flag);
        }
    
        int kthSmallest(TreeNode* root, int k) {
            int x;
            inorder(root,&x,k,false);
            return x;
        }
    };
    

    [alt text](0_1472925387421_454564654.PNG image url)


Log in to reply
 

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