diff --git a/problems/3.longest-substring-without-repeating-characters.md b/problems/3.longest-substring-without-repeating-characters.md index a36daedb9..b14da9627 100644 --- a/problems/3.longest-substring-without-repeating-characters.md +++ b/problems/3.longest-substring-without-repeating-characters.md @@ -49,7 +49,7 @@ https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ 2. 如果当前遍历到的字符出现过,则缩小窗口(左边索引向右移动),然后继续观察当前遍历到的字符; -3. 重复(1)(2),直到左边索引无法再移动; +3. 重复(1)(2),直到窗口内无重复元素; 4. 维护一个全局最大窗口 res,每次用出现过的窗口大小来更新结果 res,最后返回 res 获取结果; @@ -66,7 +66,65 @@ https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ ## 代码 -代码支持:Python3 +代码支持:C++,Java,Python3 + + +C++ Code: + +```c++ +class Solution { +public: + int lengthOfLongestSubstring(string s) { + + int ans = 0, start = 0; + int n = s.length(); + // + map mp; + + for(int i=0;i map = new HashMap<>(); + + for(int i=0;i