Skip to content

Commit 76118e6

Browse files
committed
Fixed the bug in kth smallest element in BST problem
1 parent 37b25e7 commit 76118e6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tree_problems/kth_smallest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int kthSmallest(TreeNode* root, int k)
3636
int count = countNodes(root->left);
3737
if (k <= count && root->left) {
3838
return kthSmallest(root->left, k);
39-
} else if ( k + 1 >= count && root->right) {
39+
} else if ( k > count + 1 && root->right) {
4040
return kthSmallest(root->right, k - count - 1);
4141
}
4242
return root->data;

0 commit comments

Comments
 (0)