题目给定一个字符串 s 请你找出其中不含有重复字符的最长子串的长度。解题用两个指针left和right隔离出一个子串子串内无重复字符具体实现1.right向右遍历字符串用哈希表数组记录字符在子串中出现的位置。2.遇到重复字符时left右移一位right右移一位。3.每次移动更新子串长度。#includeunordered_map#includestring#includealgorithmclassSolution{public:intlengthOfLongestSubstring(std::string s){std::unordered_mapchar,intlastPos;// 字符 - 最后出现的位置intleft0,maxLen0;for(intright0;rights.size();right){charcs[right];// 如果字符已存在且其位置在窗口内移动左指针if(lastPos.find(c)!lastPos.end()lastPos[c]left){leftlastPos[c]1;}lastPos[c]right;// 更新当前字符的位置maxLenstd::max(maxLen,right-left1);}returnmaxLen;}};