Skip to content

Instantly share code, notes, and snippets.

@piusayowale
Created June 23, 2022 12:33
Show Gist options
  • Save piusayowale/b5614fc7d7ce241f4a6d3e967e589456 to your computer and use it in GitHub Desktop.
Save piusayowale/b5614fc7d7ce241f4a6d3e967e589456 to your computer and use it in GitHub Desktop.
Given two strings, determine if they share a common substring. A substring may be as small as one character.
string twoStrings(string s1, string s2) {
set<char> f(s1.begin(), s1.end());
std::cout << s1 << "\n" << s2 << "\n\n";
for(auto i : s2){
std::cout << i << "\n";
auto ret = f.insert(i);
if(ret.second == false){
std::cout << i << " here\n";
return "YES";
}else {
f.erase(i);
}
}
return "NO";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment