File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed 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+ } ;
Original file line number Diff line number Diff line change 174174989|[ Add to Array-Form of Integer] ( ./0989-add-to-array-form-of-integer.js ) |Easy|
175175994|[ Rotting Oranges] ( ./0994-rotting-oranges.js ) |Medium|
176176997|[ Find the Town Judge] ( ./0997-find-the-town-judge.js ) |Easy|
177+ 1002|[ Find Common Characters] ( ./1002-find-common-characters.js ) |Easy|
1771781009|[ Complement of Base 10 Integer] ( ./1009-complement-of-base-10-integer.js ) |Easy|
1781791010|[ Pairs of Songs With Total Durations Divisible by 60] ( ./1010-pairs-of-songs-with-total-durations-divisible-by-60.js ) |Medium|
1791801022|[ Sum of Root To Leaf Binary Numbers] ( ./1022-sum-of-root-to-leaf-binary-numbers.js ) |Easy|
You can’t perform that action at this time.
0 commit comments