本人解法:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param Words string字符串一维数组
* @return string字符串
*/
function WordsMerge(Words) {
// write code here
let words = [...Words];
let startArr = words[0].split("");
for (let i = 1; i < words.length; i++) {
const wordArr = words[i].split("");
while (startArr.length && wordArr.length) {
if (startArr[startArr.length - 1] === wordArr[0]) {
startArr.pop();
wordArr.shift();
} else {
startArr = [...startArr, ...wordArr];
break;
}
}
}
return startArr.join("");
}
module.exports = {
WordsMerge: WordsMerge,
};