Created
July 10, 2017 16:53
-
-
Save betterkenly/abaeb8a75d62014c700da0dd9e00afe7 to your computer and use it in GitHub Desktop.
slow run time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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