var lengthOfLIS = function (nums) {
var dp = [];
for (var i = 0; i < nums.length; i++) {
dp[i] = 1;
var max = 0;
for (var j = 0; j < i; j++) {
if (nums[j] < nums[i]) {
if (dp[j] > max) {
max = dp[j]
}
}
}
dp[i] = max + 1;
}
return Math.max(...dp);
};
console.log(lengthOfLIS([23, 2, 4, 5, 6]));
var topKFrequent = function (nums, k) {
var map = {};
for (var i = 0; i < nums.length; i++) {
map[nums[i]] = map[nums[i]] ? map[nums[i]] + 1 : 1;
}
var keys = Object.keys(map);
keys.sort((a, b) => {
if (map[a] > map[b]) return -1;
if (map[a] < map[b]) return 1;
return 0;
});
// console.log(map, keys);
return keys.slice(0, k).map(a => parseInt(a));
};
console.log(topKFrequent([1, 1, 1, 2, 2, 3, 4], 2));