LeetCode每日一题 010 无重复字符的最长子串
2019-03-08 00:37
232 查看
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
1、解题思路
1)顺序遍历,依次比较每个不重复子串长度,即首尾元素相同时子串长度;
2)使用哈希表辅助判断元素是否重复
2、边界用例
3、有效题解
[code]int lengthOfLongestSubstring(char* s) { if (NULL == s || strlen(s) <= 0) { return 0; } int table[256] = {-1}; memset(table, -1, sizeof(int) * 256); int maxLen = 0; int start = -1; int i; int p1 = -1; int p2 = -1; for (i = 0; i < strlen(s); i++) { if (start < table[s[i]]) { start = table[s[i]]; } table[s[i]] = i; if (maxLen <(i - start)) { maxLen = i - start; p1 = start; p2 = i; } } return maxLen; }
4、复杂度分析
5、小结
相关文章推荐
- Leetcode每日一道 -- 无重复字符的最长子串
- [leetcode]无重复字符的最长子串
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- LeetCode 3 无重复字符的最长子串(哈希表或数组)
- LeetCode题目C++实现:3. 无重复字符的最长子串
- LeetCode给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
- LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度
- 【Leetcode一刷】3.无重复字符的最长子串
- LeetCode - 无重复字符的最长子串
- LeetCode 3. 无重复字符的最长子串 Python
- leetcode 395. 至少有K个重复字符的最长子串
- Leetcode:395至少有K个重复字符的最长子串(C++)
- 基础算法之无重复字符的最长子串(LeetCode-3)
- 【LeetCode】3.无重复字符的最长子串 结题报告 (C++)
- Leetcode 3. 无重复字符的最长子串
- LeetCode-3 无重复字符的最长子串 Longest Substring Without Repeating Characters
- [LeetCode]3. Longest Substring Without Repeating Characters寻找最长无重复字符的子串
- LeetCode 无重复字符的最长子串
- Leetcode刷题35-3.无重复字符的最长子串(C++)
- leetcode-无重复字符的最长子串(python)