Created
October 6, 2017 12:50
-
-
Save nramirez/7c6ea6e9f5e67e4ca87ae53f07b07f76 to your computer and use it in GitHub Desktop.
Longest increasing subsecuence
This file contains hidden or 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
let highest = []; | |
longest = (sequence) => { | |
var ordered = sequence.map(n => n); | |
ordered.sort((a, b) => a - b); | |
var matrix = {}; | |
const length = ordered.length; | |
for (let i = 0; i < length; i++) { | |
for(let j = 0; j < length; j++) { | |
if(ordered[i] == sequence[j]) { | |
matrix[i,j] = matrix[i-1, j] + 1; | |
} else { | |
matrix[i,j] = matrix[i-1, j]; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment