// 滑动窗口方法 function getMaxNoRepeatStr(str) { let windowSize = 1; let res = str.substring(0, 1) let i = 0 while (windowSize + i <= str.length) { if (windowSize > 1) { let tempStr = str.substring(i, i + windowSize) let tempSet = new Set(tempStr.split('')) if (tempSet.size === tempStr.length) { res = tempStr windowSize++ } else { i++ } } else { windowSize++ } } return res } console.log(getMaxNoRepeatStr('12'))