class Solution { public: TreeNode* KthNode(TreeNode* pRoot, int k) { if (!pRoot || k==0) return nullptr; array.clear(); MidTrav(array, pRoot, k); if (array.size() < k) return nullptr; return array.back(); } private: vector<TreeNode*> array; void MidTrav(vector<TreeNode*>& array, TreeNode* root, int end) { if (!root || array.size() == end) return; MidTrav(array, root->left, end); if (array.size() == end) return; array.push_back(root); MidTrav(array, root->right, end); } };