public int KthSmallestHelper(Node root, int k, Smallest smallest) { if (root == null) { return(-1); } var left = KthSmallestHelper(root.Left, k, smallest); if (left != -1) { return(left); } smallest.Count++; if (smallest.Count == k) { return(root.Data); } return(KthSmallestHelper(root.Right, k, smallest)); }
public int KthSmallest(Node root, int k) { Smallest smallest = new Smallest(); return(KthSmallestHelper(root, k, smallest)); }