diff --git a/kth smallest element in binary tree b/kth smallest element in binary tree new file mode 100644 index 0000000..13dccb0 --- /dev/null +++ b/kth smallest element in binary tree @@ -0,0 +1,11 @@ +public ArrayList list=new ArrayList<>(); + public int kthSmallest(TreeNode root, int k) { + if(root==null) return 0; + int l=kthSmallest(root.left,k); + if(l!=0) + return l; + list.add(root.val); + if(list.size()==k) return list.get(list.size()-1); + return kthSmallest(root.right,k); + + }