Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save betterkenly/abaeb8a75d62014c700da0dd9e00afe7 to your computer and use it in GitHub Desktop.
Save betterkenly/abaeb8a75d62014c700da0dd9e00afe7 to your computer and use it in GitHub Desktop.
slow run time
var kthSmallest = function(root, k) {
var result = [];
var search = (node) => {
if (node.val !== null) {
result.push(node.val);
}
if (node.left) {
search(node.left);
}
if (node.right) {
search(node.right);
}
if (node.right === null && node.left === null) {
return;
}
};
search(root);
console.log(result);
return result.sort((a,b) => {
return a - b;
})[k-1];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment