PriorityQueue Java


#1

public class Solution {
PriorityQueue result=new PriorityQueue();
public int kthsmallest(TreeNode A, int B) {

    inorder(A);
    int c=0;
    while(c<B){
        result.remove();
        c++;
    }
    return result.remove();
}

public void inorder(TreeNode root){
    
    if(root == null){
        return;
    }
    
    inorder(root.left);
    result.add(root.val);
    inorder(root.right);
}
    
}.