We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dac8f31 commit 666c0aaCopy full SHA for 666c0aa
src/leetcode2018/FindtheDifference.java
@@ -0,0 +1,25 @@
1
+package leetcode2018;
2
+
3
+import java.util.HashMap;
4
+import java.util.Map;
5
6
+public class FindtheDifference {
7
+ public char findTheDifference(String s, String t) {
8
+ Map<Character, Integer> map = new HashMap<>();
9
+ for(char c: s.toCharArray()){
10
+ map.put(c, map.getOrDefault(c,0)+1);
11
+ }
12
+ for(char c: t.toCharArray()){
13
+ if(map.containsKey(c)){
14
+ map.put(c,map.get(c)-1);
15
+ if(map.get(c) < 0)
16
+ return c;
17
18
+ else{
19
20
21
22
23
+ return ' ';
24
25
+}
0 commit comments