Title: #1426 - Counting Elements - LeetCode JavaScript Solutions
Open Graph Title: #1426 - Counting Elements - LeetCode JavaScript Solutions
X Title: #1426 - Counting Elements - LeetCode JavaScript Solutions
Description: Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them ...
Open Graph Description: Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them ...
X Description: Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/counting-elements
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/counting-elements","name":"#1426 - Counting Elements - LeetCode JavaScript Solutions","description":"Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} arr\n * @return {number}\n */\nvar countElements = function(arr) {\n const set = new Set(arr);\n return arr.filter(num => set.has(num + 1)).length;\n};","keywords":"LeetCode 1426, #1426 - Counting Elements, 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/counting-elements |
| 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/counting-elements/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/1426-counting-elements.js |
| Array | https://leetcodejavascript.com/tags/array |
| Hash Table | https://leetcodejavascript.com/tags/hash-table |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow