LeetCode-3-无重复字符的最长子串
2018-06-22 16:47
543 查看
/* 3.给定一个字符串,找出不含有重复字符的最长子串的长度 示例: 给定 "abcabcbb" ,没有重复字符的最长子串是 "abc" ,那么长度就是3。 给定 "bbbbb" ,最长的子串就是 "b" ,长度是1。 给定 "pwwkew" ,最长子串是 "wke" ,长度是3。请注意答案必须是一个子串,"pwke" 是 子序列 而不是子串。 */ public static int lengthOfLongestSubstring(String s) { if (s.length() == 0) return 0; String[] strs = s.split( "" ); int k = 1, n = 0; for (int i = 1; i < strs.length; i++) { String x = s.substring( n, i ); String y = strs[i]; if (!x.contains( y )) { if (x.length() >= k) k++; } else { int j = x.indexOf( y ); i += j + 1; n += j + 1; } } return k; }
阅读更多
相关文章推荐
- Leetcode 刷题(python)之 无重复字符的最长子串
- LeetCode - 无重复字符的最长子串
- 【LeetCode】3. 无重复字符的最长子串(Longest Substring Without Repeating Characters,24.2%,中等)
- LeetCode 3. 无重复字符的最长子串
- LeetCode 无重复字符的最长子串
- LeetCode 3. 无重复字符的最长子串 Python
- leetcode 3:无重复字符的最长子串
- 【LeetCode题目记录-3】字符串中最长的没有重复字符的子串
- [LeetCode]3. Longest Substring Without Repeating Characters寻找最长无重复字符的子串
- LeetCode 3. Longest Substring Without Repeating Characters 无重复字符的最长子串
- leetcode 3. 无重复字符的最长子串
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- [Leetcode] 3.无重复字符的最长子串
- [leetcode]无重复字符的最长子串
- 【LeetCode】无重复字符的最长子串
- LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度
- LeetCode 3 无重复字符的最长子串(哈希表或数组)
- leetcode(3)无重复字符的最长子串
- 【leetcode】第3题:求最长不重复(字符不重复)的子串的长度
- [LeetCode] Longest Substring Without Repeating Characters 无重复字符的最长子串