/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int z=0,ans=0;
int kthSmallest(struct TreeNode* root, int k) {
t(root,k);
return ans;
}
void t(struct TreeNode* r,int k)
{ // printf("C%d",z);
if(r==NULL  z>k)
{//printf("NULL");
return;}
t(r>left,k);
z++;printf("%d",r>val);
if(z==k)
{ ans=r>val;}
t(r>right,k);
}
What is wrong in my code?


Global variables?
int kthSmallest(struct TreeNode* root, int k) { int z=0,ans=0; t(root, k, &z, &ans); return ans; } void t(struct TreeNode* r,int k, int * z, int * ans) { if(r==NULL) return; t(r>left,k, z, ans); (*z)++; if((*z) == k) { *ans = r>val; return; } t(r>right,k, z, ans); }