File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 224
224
1598|[ Crawler Log Folder] ( ./1598-crawler-log-folder.js ) |Easy|
225
225
1668|[ Maximum Repeating Substring] ( ./1668-maximum-repeating-substring.js ) |Easy|
226
226
1672|[ Richest Customer Wealth] ( ./1672-richest-customer-wealth.js ) |Easy|
227
+ 1748|[ Sum of Unique Elements] ( ./1748-sum-of-unique-elements.js ) |Easy|
227
228
1780|[ Check if Number is a Sum of Powers of Three] ( ./1780-check-if-number-is-a-sum-of-powers-of-three.js ) |Medium|
228
229
1880|[ Check if Word Equals Summation of Two Words] ( ./1880-check-if-word-equals-summation-of-two-words.js ) |Easy|
229
230
1886|[ Determine Whether Matrix Can Be Obtained By Rotation] ( ./1886-determine-whether-matrix-can-be-obtained-by-rotation.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments