0%

HackerRank Set And Map 2.Two Strings

題目連結:Two Strings | HackerRank

用unordered_set比較快O(N) vs O(NlogN)

1
2
3
4
5
6
7
8
9
10
11
12
string twoStrings(string s1, string s2) {
unordered_set<char> s;
for(auto a:s1){
s.insert(a);
}
for(auto a:s2){
if(s.count(a)){
return "YES";
}
}
return "NO";
}