3. Longest Substring Without Repeating Characters
2016-09-21 20:09
183 查看
public int lengthOfLongestSubstring(String s) { if(s.length() == 0) { return 0; } int[] flag = new int[128]; int len = s.length(); int i = 0, j = 0; int max = 1, count = 0; for(i = 0; i < 128; i++) { flag[i] = -1; } for(i = 0; i < len; i++) { count = 1; int c = (int)s.charAt(i); flag[c] = i; for(j = i+1; j < len; j++) { int c2 = (int)s.charAt(j); if(flag[c2] == i) { count = j - i; break; }else { flag[c2] = i; } } if( count > max) { max =count; }else if(j >=len && (len -i) > max) { max = len -i; } } return max; }
相关文章推荐
- leetcode 003 Longest Substring Without Repeating Characters
- LeetCode算法问题7 —— Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters-最长不重复子串-滑动窗口
- (LeetCode) 3、Longest Substring Without Repeating Characters
- leetcode---longest-substring-without-repeating-characters---字符串
- 【leetcode】Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- LeetCode 149 Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters-----LeetCode
- LeetCode题库——LongestSubstringWithoutRepeatingCharacters
- longest substring without repeating characters
- [LeetCode] Longest Substring Without Repeating Characters
- Leetcode-Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- [编程练习][Longest Substring Without Repeating Characters]<LeetCode-3>
- LeetCode Longest Substring Without Repeating Characters
- leetcode第七题----- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- HashTable-3-Longest Substring Without Repeating Characters