Created
August 3, 2017 16:59
-
-
Save betterkenly/40919a176a91e91f3bbdb8d6e12a5a4e to your computer and use it in GitHub Desktop.
i tried
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
var maxEnvelopes = function(envelopes) { | |
var result = []; | |
var sorted0 = envelopes.sort((a,b) => { | |
return a[0] - b[0]; | |
}); | |
var sorted1 = envelopes.sort((a,b) => { | |
return a[1] - b[1]; | |
}); | |
for (var i = 0; i < sorted0.length; i++) { | |
if (compare(sorted0[i],sorted1[i])) { | |
result.push(sorted0[i]); | |
} | |
} | |
for(var j = 0; j < result.length - 1 ; j++) { | |
if (result[j][0] < result[j + 1][0] && result[j][1] < result[j + 1][1]) { | |
continue; | |
} else { | |
result.splice(j,1); | |
j++; | |
} | |
} | |
return result.length; | |
}; | |
var compare = function(a,b) { | |
return a.every((each, i) => { | |
return each === b[i]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment