Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int dfs(TreeNode* A, int& B) {
- if (!A) return -1;
- int candidate = dfs(A->left, B);
- if (B == 0) return candidate;
- B--;
- if (B == 0) return A->val;
- return dfs(A->right, B);
- }
- int Solution::kthsmallest(TreeNode* A, int B) {
- return dfs(A, B);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement