leetcode substring without repeating characters
2014-07-28 18:06
197 查看
本来应该一次过的,结果没想到leetcode放了一堆奇怪的字符。。
做题就该思路清晰啊。
做题就该思路清晰啊。
class Solution { public: int lengthOfLongestSubstring(string s) { int loc[255] = {0}; memset(loc,-1,sizeof(loc)); int i = 0, n = s.length(), ind, maxsize = 0, tmpsize = 0, start = 0; for (i = 0; i < n; i ++) { ind = s[i]; if(loc[ind] == -1){ loc[ind] = i; continue; } int oldloc = loc[ind]; tmpsize = i - start; if (tmpsize > maxsize)maxsize = tmpsize; i = oldloc; start = i+1; memset(loc,-1,sizeof(loc)); } tmpsize = n - start; maxsize = tmpsize > maxsize? tmpsize : maxsize; return maxsize; } };
相关文章推荐
- leetcode 3. Longest Substring Without Repeating Characters
- leetcode — 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 3, Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- LeetCode-003 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_3_Longest Substring Without Repeating Characters
- LeetCode --- 3. Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- leetcode --3. Longest Substring Without Repeating Characters
- 【leetcode】003 Longest Substring Without Repeating Characters
- leetcode-3 Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters(最长不重复子串)
- Leetcode - Longest Substring Without Repeating Characters
- LeetCode(3)Longest Substring Without Repeating Characters