c++ || inorder traversal || O(h+k) time || O(h) space.
\nSimple c++ inorder traversal with O(h+k) time and with no other extra space than call stacks ( O(h) )\n ------------------------------------------------------
![image](https://assets.leetcode.com/users/images/34b55559-6599-4b80-b99c-8302def9e8e8_1642899779.1937017.jpeg)\nSimple c++ inorder traversal with O(h+k) time and with no other extra space than call stacks ( O(h) )\n ----------------------------------------------------------here is the code below----------------------------------------------------------\n \n```\n\nclass Solution {\nprivate: \n    vector<int> res;\n    int cnt=0;\n    int ans = -1;\n    void solve(TreeNode* root, int &k)\n    {\n        if(!root) return;\n        if(cnt==k) return;\n        solve(root->left,k);\n        if(cnt<k)\n        {\n           ans = root->val;\n            cnt++;\n        }\n        solve(root->right,k); \n    }\n\t\npublic:\n    int kthSmallest(TreeNode* root, int k) {\n        //if(!root) return -1;\n        solve(root, k);\n        return ans;\n    }\n};\n```
['C']