题解 | #最长不含重复字符的子字符串#
最长不含重复字符的子字符串
http://www.nowcoder.com/practice/48d2ff79b8564c40a50fa79f9d5fa9c7
class Solution {
public:
int lengthOfLongestSubstring(string str)
{
string win = "";
int iLenMax = 1;
for(char &c : str)
{
if(win.find(c) == string::npos)
win += c;
else
{
while(win[0] != c) win.erase(0, 1);
win.erase(0, 1);
win += c;
}
iLenMax = max(iLenMax, (int)win.length());
}
return iLenMax;
}
};