Hi there. I'm using a simple inorder and a counter to find the kith element.

But I got the wrong case

Input:

[1,null,2], 2

Output:

1

Expected:

2

Here's my code and I don't understand why this happened.

```
int count = 0;
int val;
void inOrder(struct TreeNode* root, int k)
{
if (root) {
inOrder(root->left, k);
count++;
if (count == k)
val = root->val;
inOrder(root->right, k);
}
}
int kthSmallest(struct TreeNode* root, int k) {
inOrder(root, k);
return val;
}
```