LeetCode第三题无重复字符的最长子串
2019-03-26 18:10
344 查看
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
采用暴力方法,遍历整个字符串,对于每一个字符串,计算其最长子串temp,若max<temp,则temp赋值给max。时间复杂度为O(n^3),应该是有更加有效的方法的。代码如下
[code]int lengthOfLongestSubstring(char* s) { int len = strlen(s); int i,j,k; int start=-1,max=0,temp,flag=1; for(i=0;i<len;i++) { temp = 1; for(j=i+1;j<len;j++) { for(k=i;k<j;k++) { if(s[k]==s[j]) flag=0; } if(flag==1) { temp++; } else { flag=1; break; } } if(temp>max) max=temp; } return max; }
相关文章推荐
- leetcode第三题:无重复字符的最长子串
- 【LeetCode】第三题:无重复字符的最长子串
- C#leetcode刷题3无重复字符的最长子串
- LeetCode-3 无重复字符的最长子串 Longest Substring Without Repeating Characters
- LeetCode 3. Longest Substring Without Repeating Characters 无重复字符的最长子串
- LeetCode-3-无重复字符的最长子串
- Leetcode 3. 无重复字符的最长子串
- leetcode-最长无重复字符的子串
- 【LeetCode】3. 无重复字符的最长子串(Longest Substring Without Repeating Characters,24.2%,中等)
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- LeetCode 3. 无重复字符的最长子串 Python
- leetcode 3. 无重复字符的最长子串
- LeetCode题库解答与分析——#3.无重复字符的最长子串LongestSubstringWithoutRepeatingCharacters
- leetcode第三题: 输出不包含重复字母的最长子串
- Leetcode(C++)——3. 无重复字符的最长子串
- LeetCode 3. 无重复字符的最长子串
- Leetcode刷题35-3.无重复字符的最长子串(C++)
- LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度
- [Leetcode] 3.无重复字符的最长子串
- LeetCode - 无重复字符的最长子串