class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param Words string字符串vector
* @return string字符串
*/
string WordsMerge(vector<string>& Words) {
// write code here
string ans;
for(int i = 1; i < Words.size(); i++) {
ans = merge(Words[i-1], Words[i]);
}
return ans;
}
string merge(string& a, string& b) {
int a_n = a.size(), b_n = b.size();
int i,j;
for(i = a_n-1, j = 0; i >=0 && j < b_n; i--, j++) {
if(a[i] != b[j])
break;
}
return a.substr(0,i+1) + b.substr(j,b_n-j);
}
};