3 無重複字元的最長子串
注意兩點:
- 需要多次判重,就考慮使用
unordered_map
(雜湊實現),或者map
(紅黑樹)。 - 如果集合元素固定且數量不多,可直接使用桶方法。
程式碼如下:
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int maxlen = 0, start = 0;
vector<int> a(128,-1);
for(int i = 0; i < s.size(); i++) {
int x = a[int(s[i])];
if(x >= start) start = x + 1;
a[int(s[i])] = i;
maxlen = maxlen > i - start + 1 ? maxlen : i - start + 1;
}
return maxlen;
}
};
相關文章
- 3. 無重複字元的最長子串字元
- 無重複字元的最長子串字元
- java無重複字元的最長子串Java字元
- 【LeetCode】3 無重複字元的最長子串LeetCode字元
- 【leetcode】【java】【3、無重複字元的最長子串】LeetCodeJava字元
- leetcode-3無重複字元的最長子串LeetCode字元
- LeetCode-3. 無重複字元的最長子串LeetCode字元
- Leetcode 3. 無重複字元的最長子串LeetCode字元
- LeetCode——無重複字元的最長子串LeetCode字元
- 演算法-無重複字元的最長子串演算法字元
- 每日leetcode——3. 無重複字元的最長子串LeetCode字元
- leetcode 之無重複字元的最長子串LeetCode字元
- [LeetCode 刷題] 3. 無重複字元的最長子串 (Medium)LeetCode字元
- #leetcode刷題之路3-無重複字元的最長子串LeetCode字元
- LCR 016. 無重複字元的最長子串(中)字元
- 求字串中不含重複字元的最長子串字串字元
- 無重複字元的最長子串問題 (移動視窗法求解)字元
- Leetcode 3.無重複字元的最長子串 字典記錄每個字元最後出現的位置LeetCode字元
- LeetCode3:Longest Substring Without Repeating Characters(無重複字元的最長子串)LeetCode字元
- Leetcode[字串] 3. 無重複字元的最長子串 10行極簡寫法!LeetCode字串字元
- 每天一道演算法題:無重複字元的最長子串演算法字元
- LeetCode133:給定一個字串,找出最長的不具有重複字元的子串的長度。例如,“abcabcbb”不具有重複字元的最長子串是“abc”,長度為3。對於“bbbbb”,最長的不具有重複字元的子串是LeetCode字串字元
- 讓我們一起啃演算法----無重複字元的最長子串演算法字元
- [LeetCode] Longest Substring Without Repeating Characters 最長無重複字元的子串LeetCode字元
- 最長不含重複字元的子字串字元字串
- 滑動視窗3.替換後最長重複字元子串字元
- 用滑動視窗來解決最長無重複子串問題
- leetcode 解題 3. 無重複字元的最長子串-python3@ 官方,暴力解法和視窗滑動解法LeetCode字元Python
- 用 PHP 在 力扣 上演算法 [無重複字元的最長子串]{一天一更}PHP力扣演算法字元
- JZ-073-最長不含重複字元的子字串字元字串
- 【Leetcode】3. Longest Substring Without RepeatingCharacters無重最長子串LeetCodeGC
- 劍指 Offer 48. 最長不含重複字元的子字串字元字串
- (字串雜湊表)找到字串中不重複出現字元的最長子串長度字串字元
- 最長子串
- SPOJ 687. Repeats(字尾陣列求最長重複子串)陣列
- 演算法練習:求字串的最長重複子串(Java實現)演算法字串Java
- leetcode無重複字元的最長字串 python實現LeetCode字元字串Python
- POJ 3693 Maximum repetition substring(字尾陣列求最長重複子串)陣列