Doing this problem: https://leetcode.com/problems/kth-smallest-element-in-a-bst/
Solution:
Stack<TreeNode> stack = new Stack<>();
while(root != null || !stack.isEmpty()) {
while(root != null) {
stack.push(root);
root = root.left;
}
root = stack.pop();
if(--k == 0) break;
root = root.right;
}
return root.val; }
Example Walkthrough: https://repl.it/@Stylebender/Kth-Smallest-BST
Just wondering why the answer I get from my walkthrough (5) doesn't seem to be correct answer(4).