算法题---最长不含重复字符的子字符串

// 遍历字符串,使用set集合记录走过的字符

//
字符串不含重复字符的最长子串 int longChirldStr(string s){ set<char> tmpSet; int ret = 0; int right = 0; int size = s.length(); if(size ==0 || size == 1){ return size; } for(int i=0; i<size; i++){ while(right < size && !tmpSet.count(s[right])){ tmpSet.insert(s[right]); right++; } ret = max(ret, right-i); tmpSet.erase(s[i]); } return ret; }

 

posted @ 2020-11-02 09:30  威威后花园  阅读(80)  评论(0编辑  收藏  举报