Skip to content

Instantly share code, notes, and snippets.

@JacksonRMC
Created May 22, 2017 16:47
Show Gist options
  • Save JacksonRMC/0f53fbac1a6f4ff13e7e056463891a01 to your computer and use it in GitHub Desktop.
Save JacksonRMC/0f53fbac1a6f4ff13e7e056463891a01 to your computer and use it in GitHub Desktop.
var kthSmallest = function(root, k) {
var potentialSmall = root.val;
var counter = 0;
var numbers = [root.val];
var go = true;
var test = function(x){
if( !x.right || !x.left ){
return numbers;
} else {
var nodes = [x.right, x.left];
for( var i = 0; i < nodes.length; i ++){
numbers.push(nodes[i].val);
test(nodes[i]);
}
}
}
test(root);
return numbers.sort()[k - 1]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment