LeetCode – Kth Smallest Element in a BST (Java)
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. (1 ≤ k ≤ BST’s total elements) Java Solution 1 – Inorder Traversal We can inorder traverse the tree and get the kth smallest element. Time is O(n). public int kthSmallest(TreeNode root, int k) { Stack<TreeNode> stack = … Read more