Skip to content

Commit e7bfb8b

Browse files
committedJan 10, 2022
Add solution #1748
1 parent 834e987 commit e7bfb8b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
225225
1668|[Maximum Repeating Substring](./1668-maximum-repeating-substring.js)|Easy|
226226
1672|[Richest Customer Wealth](./1672-richest-customer-wealth.js)|Easy|
227+
1748|[Sum of Unique Elements](./1748-sum-of-unique-elements.js)|Easy|
227228
1780|[Check if Number is a Sum of Powers of Three](./1780-check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
228229
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
229230
1886|[Determine Whether Matrix Can Be Obtained By Rotation](./1886-determine-whether-matrix-can-be-obtained-by-rotation.js)|Easy|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 1748. Sum of Unique Elements
3+
* https://leetcode.com/problems/sum-of-unique-elements/
4+
* Difficulty: Easy
5+
*
6+
* You are given an integer array nums. The unique elements of an array are the
7+
* elements that appear exactly once in the array.
8+
*
9+
* Return the sum of all the unique elements of nums.
10+
*/
11+
12+
/**
13+
* @param {number[]} nums
14+
* @return {number}
15+
*/
16+
var sumOfUnique = function(nums) {
17+
const map = new Map();
18+
nums.forEach(n => map.set(n, (map.get(n) || 0) + 1));
19+
20+
return [...map].reduce((sum, [key, value]) => {
21+
return sum + (value === 1 ? key : 0);
22+
}, 0);
23+
};

0 commit comments

Comments
 (0)
Please sign in to comment.