lgwebdream / FE-Interview

🔥🔥🔥 前端面试,独有前端面试题详解,前端面试刷题必备,1000+前端面试真题,Html、Css、JavaScript、Vue、React、Node、TypeScript、Webpack、算法、网络与安全、浏览器
https://lgwebdream.github.io/FE-Interview/
Other
6.76k stars 897 forks source link

字符串不重复出现的最大长度 #1159

Closed LLLarry closed 3 years ago

LLLarry commented 3 years ago

function maxLength (str) { let maxValue = 0 function tt (index) { let newStr = '' for (let i = index; i < str.length; i++) { if (!newStr.includes(str[i])) { newStr += str[i] maxValue = Math.max(maxValue, newStr.length) } else { if (index + 1 <= str.length) { tt(index + 1) } } } } tt(0) return maxValue }