Longest Substring Without Repeating Characters[leetcode]
2014-09-14 11:57
288 查看
记录最大的起始位置+hash
int lengthOfLongestSubstring(string s) { map<char, int> charMap; int curLen, maxLen = 0,lastIndex = -1; for (int i = 0; i < s.size(); i++) { if (charMap.find(s[i]) != charMap.end() && lastIndex < charMap[s[i]]) lastIndex = charMap[s[i]]; curLen = i - lastIndex; maxLen = max(maxLen,curLen); charMap[s[i]] = i; } return maxLen; }
相关文章推荐
- Leetcode: Longest Substring Without Repeating Characters
- LeetCode:Longest Substring Without Repeating Characters(update)
- LeetCode-003 Longest Substring Without Repeating Characters
- leetcode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- Leetcode | Longest Substring Without Repeating Characters
- Leetcode-3-Longest Substring Without Repeating Characters
- leetcode-3 Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- leetcode — longest-substring-without-repeating-characters
- LeetCode Longest Substring Without Repeating Characters
- leetcode:Longest Substring Without Repeating Characters
- LeetCode - 3 - Longest Substring Without Repeating Characters
- 4000 【LeetCode】 Longest Substring Without Repeating Characters(Java)
- Leetcode(3)-Longest Substring Without Repeating Characters
- LeetCode|Longest Substring Without Repeating Characters
- Leetcode_Longest Substring Without Repeating Characters
- LeetCode3 Longest Substring Without Repeating Characters
- leetcode:Longest Substring Without Repeating Characters (寻找最长无重复字符的子串)
- 【leetcode】 Longest Substring Without Repeating Characters