Why my C++ solution TLE?


  • -1
    R
    int lengthOfLongestSubstring(string s) {
    	std::map<int, int> info;
    	int len = s.size();
    	int m = 0, c;
    	for (int i = 0, j = i; j < len;) {
    		if (info[s[j]-'\0'] != j + 1 && info[s[j]-'\0'] >= i + 1) {
    			if (c > m)
    				m = c;
    			i = info[s[j]-'\0'];
    			j = i;
    			c = 0;
    			continue;
    		} else {
    			++c;
    			info[s[j]-'\0'] = j + 1;
    			++j;
    		}
    	}
    	return c>m?c:m;
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.