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 703cbe0 commit f770374Copy full SHA for f770374
kth-smallest-element-in-a-bst/Raft.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
3
+ stack = []
4
+
5
+ while True:
6
+ while root:
7
+ stack.append(root)
8
+ root = root.left
9
+ root = stack.pop()
10
+ k -= 1
11
+ if not k:
12
+ return root.val
13
+ root = root.right
14
+# T: O(n)
15
+# S: O(n)
16
0 commit comments