LeetCode-滑动窗口-3. 无重复字符的最长子串
生活随笔
收集整理的這篇文章主要介紹了
LeetCode-滑动窗口-3. 无重复字符的最长子串
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
3. 無重復字符的最長子串
思路:滑動窗口
class Solution { public:int lengthOfLongestSubstring(string s) {if(s.empty()) return 0;int maxSize = 0;int left = 0;unordered_set<char> lookup;for(int i=0;i<s.size();i++){while(lookup.find(s[i])!=lookup.end()){lookup.erase(s[left]);left++;}lookup.insert(s[i]);maxSize = max(maxSize,i-left+1);}return maxSize;} };劍指off
總結
以上是生活随笔為你收集整理的LeetCode-滑动窗口-3. 无重复字符的最长子串的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vue学习(一)-邂逅Vuejs
- 下一篇: LeetCode-链表-160. 相交链