LeetCode 3. 无重复字符的最长子串
2018-02-27 22:42
513 查看
https://leetcodechina.com/problems/longest-substring-without-repeating-characters/description/
有点dp的意思
dp[i]:末尾为i位置的不含有重复字符的 最长子串 的长度
dp[i]=max(vis[s[i]]+1,i+1-dp[i-1])~~~i
t代表i-1时不含有重复字符的 最长子串的最左位置
有点dp的意思
dp[i]:末尾为i位置的不含有重复字符的 最长子串 的长度
dp[i]=max(vis[s[i]]+1,i+1-dp[i-1])~~~i
t代表i-1时不含有重复字符的 最长子串的最左位置
class Solution { public: int lengthOfLongestSubstring(string s) { int vis[130], ans = 0, t = 0; memset(vis, -1, sizeof(vis)); for (int i = 0; i < s.size(); ++i) t = max(vis[s[i]]+1, t), ans = max(ans, i - t + 1), vis[s[i]] = i; return ans; } };
相关文章推荐
- 【LeetCode】3.无重复字符的最长子串 结题报告 (C++)
- Leetcode 3. 无重复字符的最长子串
- 【LeetCode题目记录-3】字符串中最长的没有重复字符的子串
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- [LeetCode] Longest Substring Without Repeating Characters 无重复字符的最长子串
- 3.无重复字符的最长子串(Longest Substring Without Repeating Characters)
- Leetcode 刷题(python)之 无重复字符的最长子串
- leetcode:Longest Substring Without Repeating Characters (寻找最长无重复字符的子串)
- LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度
- LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium
- [LeetCode]3. Longest Substring Without Repeating Characters寻找最长无重复字符的子串
- [leetcode]Longest Substring Without Repeating Characters【最长不重复字符子串】
- 3. 无重复字符的最长子串
- LeetCode - 无重复字符的最长子串
- [leetcode]无重复字符的最长子串
- [leetcode]获取字符串中字符不重复的最长子串的长度
- LeetCode题库解答与分析——#3.无重复字符的最长子串LongestSubstringWithoutRepeatingCharacters
- 【leetcode】第3题:求最长不重复(字符不重复)的子串的长度
- 【中级算法】3. 无重复字符的最长子串
- 3. 无重复字符的最长子串(O(N))