Leetcode 3. 无重复字符的最长子串
2018-07-23 16:14
671 查看
class Solution { public: int lengthOfLongestSubstring(string s) { int beg = 0; int result = 0; string word = ""; int char_map[128] = {0}; for(int i=0; i<s.size(); ++i) { char_map[s[i]]++; if(char_map[s[i]] == 1)// 没有出现过 { word+=s[i]; if(result < word.size()) result = word.size(); } else//已经出现过了 { while(beg <i && char_map[s[i]] > 1) { char_map[s[beg]]--; beg++; } word = ""; for(int j=beg; j<=i ;++j) word+=s[j]; } } return result; } };
相关文章推荐
- 【LeetCode】3.无重复字符的最长子串 结题报告 (C++)
- LeetCode 3. 无重复字符的最长子串
- [LeetCode]3. Longest Substring Without Repeating Characters寻找最长无重复字符的子串
- 3. 无重复字符的最长子串(O(N))
- [LeetCode] Longest Substring Without Repeating Characters 无重复字符的最长子串
- 【中级算法】3. 无重复字符的最长子串
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- Leetcode 刷题(python)之 无重复字符的最长子串
- [leetcode]Longest Substring Without Repeating Characters【最长不重复字符子串】
- 3.无重复字符的最长子串(Longest Substring Without Repeating Characters)
- [leetcode]无重复字符的最长子串
- leetcode-最长无重复字符的子串
- LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium
- LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度
- LeetCode - 无重复字符的最长子串
- 【leetcode】第3题:求最长不重复(字符不重复)的子串的长度
- 3. 无重复字符的最长子串
- leetcode:Longest Substring Without Repeating Characters (寻找最长无重复字符的子串)
- 【LeetCode题目记录-3】字符串中最长的没有重复字符的子串
- [leetcode]获取字符串中字符不重复的最长子串的长度