We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
index.ts
export function topKFrequent(nums: number[], k: number): number[] { const frequencyMap = new Map<number, number>(); nums.map((num) => { const count = frequencyMap.has(num) ? frequencyMap.get(num) : 0; frequencyMap.set(num, (count ?? 0) + 1); }); const uniqueNums = Array.from(frequencyMap.keys()); return uniqueNums .sort((a, b) => { return (frequencyMap.get(b) ?? 0) - (frequencyMap.get(a) ?? 0); }) .slice(0, k); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
index.ts
The text was updated successfully, but these errors were encountered: