image.png
    image.png

    1. let str = 'asdfesauiodb';
    2. function foo(str){
    3. const len =str.length;
    4. let i = 0;
    5. let j = 0;
    6. let ans = 0;
    7. function fn(){
    8. if(str.substring(i,j).indexOf(str[j])<0){
    9. j++
    10. } else {
    11. i++
    12. }
    13. ans = Math.max(ans,j);
    14. if(i<=j&&j<len){
    15. return fn();
    16. } else {
    17. console.log("最长字符串为:"+str.slice(i,ans));
    18. }
    19. }
    20. fn();
    21. }
    22. foo(str)