Simple C# Solution


  • 0
    B
    public class Solution {
    public int KthSmallest(TreeNode root, int k) {
        if(root == null) return 0;
        var result = new List<int>();
        InOrder(root, result,k);
        return result[k-1];
    }
    
    public void InOrder(TreeNode node, List<int> result, int kth){
        if(node == null) return;
        if(result.Count == kth) return;
        InOrder(node.left, result, kth);
        result.Add(node.val);
        InOrder(node.right, result, kth);
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.