JAVA Brute Force


  • 0
    D
    class Solution
    {
        ArrayList<Integer> nums = new ArrayList<Integer>();
        public int kthSmallest(TreeNode root, int k)
        {
        	itr(root);
        	Collections.sort(nums);
        	return nums.get(k-1);
        	
        }
        public void itr(TreeNode r)
        {
        	if(r != null)
        	{
        		nums.add(r.val);
        		itr(r.left);
        		itr(r.right);
        	}
        }
    }
    

Log in to reply
 

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