Skip to content

Instantly share code, notes, and snippets.

@joshuashaffer
Created October 15, 2017 16:12
Show Gist options
  • Save joshuashaffer/3db7ad71bb6338f313b4f41ac2658168 to your computer and use it in GitHub Desktop.
Save joshuashaffer/3db7ad71bb6338f313b4f41ac2658168 to your computer and use it in GitHub Desktop.
Given two strings s1 and s2, merge them into one string by overlapping the suffix of the first string and the prefix of the second string. If there's nothing to concatenate, return the concatenation of the strings.
#define x substr
auto singkatan(auto w, auto q) {
int a=w.length(),b=q.length(),m=a<b?a:b;
while(m--)if(w.x(a-m-1,m+1)==q.x(0,m+1))q=q.x(m+1,b-m);
return w+q;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment