lintcode-384

来源:互联网 发布:aspen8.4软件下载 编辑:程序博客网 时间:2024/05/21 00:53
class Solution {public:    /**     * @param s: a string     * @return: an integer      */    int lengthOfLongestSubstring(string s) {        // write your code here        if(0==s.size())            return 0;        if(1==s.size())            return 1;        map<char,int> check;        int max=INT_MIN,size=s.size(),count=0;            int i=0;        while(i<size){            if(check[s[i]]){                i=check[s[i]];                check.clear();                    if(count>max)                    max=count;                count=0;                }else{                check[s[i]]=i+1;                ++i;                ++count;            }        }        return max>count?max:count;    }};

0 0