Created
May 22, 2017 16:47
-
-
Save JacksonRMC/0f53fbac1a6f4ff13e7e056463891a01 to your computer and use it in GitHub Desktop.
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 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