leetcode 3.无重复字符的最长子串
2018-12-10 20:18
369 查看
leetcode 3:给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度.
[code]示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 示例 2: 输入: "bbbbb" 输出: 1 解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。
[code]class Solution { public: int lengthOfLongestSubstring(string s) { vector<int> m(256, -1); int res = 0, left = -1; for(int i = 0; i < s.size(); ++i) { left = max(left, m[s[i]]); m[s[i]] = i; res = max(res, i-left); } return res; } };
相关文章推荐
- 【Leetcode一刷】3.无重复字符的最长子串
- LeetCode 3. 无重复字符的最长子串
- [Leetcode] 3.无重复字符的最长子串
- 【LeetCode】3.无重复字符的最长子串 结题报告 (C++)
- LeetCode 3. 无重复字符的最长子串
- LeetCode 3. 无重复字符的最长子串 Python
- Leetcode 3. 无重复字符的最长子串
- 【LeetCode】3. 无重复字符的最长子串(Longest Substring Without Repeating Characters,24.2%,中等)
- leetcode 3. 无重复字符的最长子串
- leetcode之路 3. 无重复字符的最长子串
- [LeetCode] Longest Substring Without Repeating Characters 无重复字符的最长子串
- LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度
- Leetcode:395至少有K个重复字符的最长子串(C++)
- 【中级算法】3. 无重复字符的最长子串
- 3.无重复字符的最长子串(Longest Substring Without Repeating Characters)
- leetcode:Longest Substring Without Repeating Characters (寻找最长无重复字符的子串)
- LeetCode 无重复字符的最长子串
- leetcode-最长无重复字符的子串
- Leetcode每日一道 -- 无重复字符的最长子串
- 3. 无重复字符的最长子串