leetcode-字节备考
无重复字符的最长子串给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。滑动窗口解法:1234567891011121314class Solution {public: int lengthOfLongestSubstring(string s) { unordered_map<char, int> dic; int i = -1, res = 0, len = s.size(); for(int j = 0; j < len; j++) { if (dic.find(s[j]) != dic.end()) i = max(i, dic.find(s[j])->second); // 更新左指针 dic[s[j]] = j; // 哈希表记录 res = max(res, j - i); // 更新结果 } return res;
...