Title: #169 - Majority Element - LeetCode JavaScript Solutions
Open Graph Title: #169 - Majority Element - LeetCode JavaScript Solutions
X Title: #169 - Majority Element - LeetCode JavaScript Solutions
Description: Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You ma...
Open Graph Description: Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You ma...
X Description: Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You ma...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/majority-element
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/majority-element","name":"#169 - Majority Element - LeetCode JavaScript Solutions","description":"Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You ma...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} nums\n * @return {number}\n */\nvar majorityElement = function(nums) {\n const map = new Map();\n nums.forEach(n => map.set(n, (map.get(n) || 0) + 1));\n\n const sorted = [...map].sort(([,a], [,b]) => b - a);\n return sorted[0][0];\n};","keywords":"LeetCode 169, #169 - Majority Element, Easy, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/majority-element |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/majority-element/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0169-majority-element.js |
| Array | https://leetcodejavascript.com/tags/array |
| Hash Table | https://leetcodejavascript.com/tags/hash-table |
| Sorting | https://leetcodejavascript.com/tags/sorting |
| Counting | https://leetcodejavascript.com/tags/counting |
| Divide and Conquer | https://leetcodejavascript.com/tags/divide-and-conquer |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow