Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- void f(TreeNode* root, int k, int &counter, int &ans){
- if(root==NULL)return;
- f(root->left, k, counter,ans);
- counter++;
- if(counter==k){
- ans = root->val;
- }
- f(root->right, k,counter,ans);
- }
- int kthSmallest(TreeNode* root, int k) {
- int counter = 0;
- int ans;
- f(root, k, counter, ans);
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement