3、Longest Substring Without Repeating Characters
2015-01-21 15:08
197 查看
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without
repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
Hash
Table Two Pointers String
repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
Hash
Table Two Pointers String
int lengthOfLongestSubstring(string s) { int place[128]; for (int i = 0; i < 128; ++i) place[i] = -1; int length = s.size(); int maxLength = 0, maxIndex = -1; for (int i = 0; i < length; ++i) { //此方法比较取巧,可能一眼难以理解,此题中关于哈希表的应用也是不大清楚 maxIndex = max(place[s[i]], maxIndex); maxLength = max(i - maxIndex, maxLength); place[s[i]] = i; } return maxLength; }
相关文章推荐
- 3. Longest Substring Without Repeating Characters
- 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
- Longest Substring Without Repeating Characters
- 【一天一道LeetCode】 #3 Longest Substring Without Repeating Characters
- 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
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters(LeetCode)
- leetcode:Longest Substring Without Repeating Characters
- LeetCode题解:3. Longest Substring Without Repeating Characters
- 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