We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a5c74e0 commit 5810c77Copy full SHA for 5810c77
solution/0230.Kth Smallest Element in a BST/Solution.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int kthSmallest(TreeNode root, int k) {
3
+ Deque<TreeNode> stack = new ArrayDeque<>();
4
+ while (!stack.isEmpty() || root != null) {
5
+ while (root != null) {
6
+ stack.push(root);
7
+ root = root.left;
8
+ }
9
+ root = stack.pop();
10
+ if (--k == 0) {
11
+ return root.val;
12
13
+ root = root.right;
14
15
+ return 0;
16
17
+}
0 commit comments