C++ Easiest solution using sorting
This solution made the question feel very easy. I don\'t think it was meant to be solved like this, but still this solution is accepted and is fast.\n\n\n\n\nSo
This solution made the question feel very easy. I don\'t think it was meant to be solved like this, but still this solution is accepted and is fast.\n\n![image](https://assets.leetcode.com/users/images/fcf32e96-7cbc-47dd-bd62-0cae60f7c88c_1636271340.9211264.jpeg)\n<br>\n\nSolution :-<br>\n1) Iterate through the entire tree\n2) Store all elements in an array or vector\n3) Sort the vector\n4) Return `[k - 1]` value of the sorted vector (since tree is <b>"1-indexed"</b>)\n<br>\n\nCode :-\n\n```\nclass Solution {\npublic:\n    void dfs(TreeNode* root, vector<int>& nums){\n        if(!root)\n            return;\n        \n        nums.push_back(root -> val);\n        \n        dfs(root -> left, nums);\n        dfs(root -> right, nums);\n    }\n    \n    int kthSmallest(TreeNode* root, int k) {\n        vector<int> nums;\n        \n        dfs(root, nums);\n        \n        sort(nums.begin(), nums.end());\n        \n        return nums[k - 1];\n    }\n};\n```
['C', 'Sorting', 'C++']