-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathFindTheDifference.cpp
More file actions
35 lines (32 loc) · 855 Bytes
/
Copy pathFindTheDifference.cpp
File metadata and controls
35 lines (32 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Solution {
public:
struct count{
int orig;
int modi;
};
char findTheDifference(string s, string t) {
map<char, count> myMap;
for(long long int i = 0; i < s.size(); i++){
auto it = myMap.find(s[i]);
if(it == myMap.end()){
myMap[s[i]].orig = 1;
myMap[s[i]].modi = 0;
}
else{
myMap[s[i]].orig++;
}
}
for(long long int i = 0; i < t.size(); i++){
if(myMap.find(t[i]) == myMap.end()){
return t[i];
}
else{
myMap[t[i]].modi++;
if((myMap[t[i]].orig) < (myMap[t[i]].modi)){
return t[i];
}
}
}
return NULL;
}
};