File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 174
174
989|[ Add to Array-Form of Integer] ( ./0989-add-to-array-form-of-integer.js ) |Easy|
175
175
994|[ Rotting Oranges] ( ./0994-rotting-oranges.js ) |Medium|
176
176
997|[ Find the Town Judge] ( ./0997-find-the-town-judge.js ) |Easy|
177
+ 1002|[ Find Common Characters] ( ./1002-find-common-characters.js ) |Easy|
177
178
1009|[ Complement of Base 10 Integer] ( ./1009-complement-of-base-10-integer.js ) |Easy|
178
179
1010|[ Pairs of Songs With Total Durations Divisible by 60] ( ./1010-pairs-of-songs-with-total-durations-divisible-by-60.js ) |Medium|
179
180
1022|[ Sum of Root To Leaf Binary Numbers] ( ./1022-sum-of-root-to-leaf-binary-numbers.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1002. Find Common Characters
3
+ * https://leetcode.com/problems/find-common-characters/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given a string array words, return an array of all characters that show up in all strings within
7
+ * the words (including duplicates). You may return the answer in any order.
8
+ */
9
+
10
+ /**
11
+ * @param {string[] } words
12
+ * @return {string[] }
13
+ */
14
+ var commonChars = function ( words ) {
15
+ return words
16
+ . map ( word => [ ...word ] )
17
+ . reduce ( ( common , word ) => common . filter ( s => {
18
+ const index = word . indexOf ( s ) ;
19
+ if ( index !== - 1 ) {
20
+ word . splice ( index , 1 ) ;
21
+ }
22
+ return index !== - 1 ;
23
+ } ) , [ ...words [ 0 ] ] ) ;
24
+ } ;
You can’t perform that action at this time.
0 commit comments