My problem is that I want to return a common substring of two strings s1, s2. Apparently, s1 and s2 are symmetric.
string shortest_common( const string& s1, const string& s2 ) {
}
There are three possible solutions to this problem that I came up with:
- Either make a copy of s1 and s2
- Or swap them, which means I have to sacrifice their const-ness
- Or worst, duplicate code!
I personally prefer the first case, since intent is to find the shortest-common string not changing s1 or s2. So my question is: Which option is ideal in this case?
Thanks,
Chan