LeetCode Longest Substring Without Repeating Characters 最长不重复子串
2015-04-07 21:18
537 查看
class Solution { public: int lengthOfLongestSubstring(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int locs[256];//保存字符上一次出现的位置 memset(locs, -1, sizeof(locs)); int idx = -1, max = 0;//idx为当前子串的开始位置-1 for (int i = 0; i < s.size(); i++) { if (locs[s[i]] > idx)//如果当前字符出现过,那么当前子串的起始位置为这个字符上一次出现的位置+1 { idx = locs[s[i]]; } if (i - idx > max) { max = i - idx; } locs[s[i]] = i; } return max; } };
Longest Substring Without Repeating Characters
上面代码一字不差复制过来了。
相关文章推荐
- leetcode 3 : Longest Substring Without Repeating Characters 最长无重复子串 (C# 语言版)
- leetcode(三)—— Longest Substring Without Repeating Characters(最长不重复子串 Python/C++)
- Leetcode Longest Substring Without Repeating Characters(最长不重复子串)
- [C++]LeetCode 3: Longest Substring Without Repeating Characters(最长不重复子串)
- LeetCode:Longest Substring Without Repeating Characters(最长不重复子串)
- [leetcode]Longest Substring Without Repeating Characters【最长不重复字符子串】
- 【LeetCode】4. Longest Substring Without Repeating Characters 最长无重复子串
- [LeetCode] Longest substring without repeating characters 最长无重复子串
- 【LeetCode】Longest Substring Without Repeating Characters && 【九度】题目1530:最长不重复子串
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium
- LeetCode题库解答与分析——#3.无重复字符的最长子串LongestSubstringWithoutRepeatingCharacters
- 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] Longest Substring Without Repeating Characters 无重复字符的最长子串
- leetcode 3 Longest Substring Without Repeating Characters最长无重复子串
- leetcode-Longest Substring Without Repeating Characters 最长不重复子串
- leetcode 3 Longest Substring Without Repeating Characters最长无重复子串