Created
June 23, 2022 12:33
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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