Best solution in java -->


#1

public class Solution {
public int kthsmallest(TreeNode A, int B) {

    ArrayList<Integer> a = new ArrayList<>() ;
    
    if( A == null ) return A.val ;
    
     inoder( A , a  )  ;
     
     return a.get(B-1) ;
    
}

public void  inoder( TreeNode A , ArrayList a  )
{
    if( A == null )  return  ;
    
    inoder( A.left ,  a  ) ;
    
    a.add( A.val ) ;
    
    inoder( A.right ,  a  ) ;
    
    
}

}