Skip to content

Commit ec5c902

Browse files
committed
389
1 parent c88c389 commit ec5c902

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

389-find-the-difference.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string} s
3+
* @param {string} t
4+
* @return {character}
5+
*/
6+
var findTheDifference = function(s, t) {
7+
let newMapS = new Map();
8+
9+
for(let i = 0; i < s.length; i++) {
10+
newMapS.set(s[i], (newMapS.get(s[i]) || 0) + 1);
11+
}
12+
13+
for (let j = 0; j < t.length; j++) {
14+
if (!newMapS.has(t[j]) || newMapS.get(t[j]) === 0) {
15+
return t[j];
16+
}
17+
newMapS.set(t[j], newMapS.get(t[j]) - 1);
18+
}
19+
};

0 commit comments

Comments
 (0)