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
1
+ /**
2
+ * 389. Find the Difference
3
+ * https://leetcode.com/problems/find-the-difference/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given two strings s and t.
7
+ *
8
+ * String t is generated by random shuffling string s and then add one more letter at
9
+ * a random position.
10
+ *
11
+ * Return the letter that was added to t.
12
+ */
13
+
14
+ /**
15
+ * @param {string } s
16
+ * @param {string } t
17
+ * @return {character }
18
+ */
19
+ var findTheDifference = function ( s , t ) {
20
+ const map = new Map ( ) ;
21
+ t . split ( '' ) . forEach ( c => map . set ( c , ( map . get ( c ) ?? 0 ) + 1 ) ) ;
22
+ s . split ( '' ) . forEach ( c => map . set ( c , map . get ( c ) - 1 ) ) ;
23
+ return Array . from ( map ) . find ( ( [ letter , count ] ) => count ) [ 0 ] ;
24
+ } ;
Original file line number Diff line number Diff line change 182
182
374|[ Guess Number Higher or Lower] ( ./0374-guess-number-higher-or-lower.js ) |Medium|
183
183
383|[ Ransom Note] ( ./0383-ransom-note.js ) |Easy|
184
184
387|[ First Unique Character in a String] ( ./0387-first-unique-character-in-a-string.js ) |Easy|
185
+ 389|[ Find the Difference] ( ./0389-find-the-difference.js ) |Easy|
185
186
392|[ Is Subsequence] ( ./0392-is-subsequence.js ) |Easy|
186
187
394|[ Decode String] ( ./0394-decode-string.js ) |Medium|
187
188
395|[ Longest Substring with At Least K Repeating Characters] ( ./0395-longest-substring-with-at-least-k-repeating-characters.js ) |Medium|
You can’t perform that action at this time.
0 commit comments