Kth Smallest Element in a BST (Leetcode 230) [Optimisation Required]
Problem Link: https://leetcode.com/problems/kth-smallest-element-in-a-bst/
class Solution:
def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
def fun(root):
if(root is None):
return
fun(root.left)
ans.append(root.val)
fun(root.right)
ans=[]
fun(root)
return ans[k-1]
PreviousTwo Sum IV - Input is a BST (Leetcode 653) [Optimisation Required]NextSubtree of Another Tree (Leetcode 572) [Optimisation required]
Last updated