How can I solve the problem?----Runtime error


  • 0
    X
    class Solution {
      public:
    int lengthOfLongestSubstring(string s) {
    	int m = s.size();
    	int max = 0;
    	if (!m)
    	{
    		return 0;
    	}
    	char word[26];
    	for (int i = 0; i<m; i++)
    	{
    		memset(word, 0, 26 * sizeof(char));
    		
    		int j;
    		for (j = i; j<m; j++)
    		{
    			if (word[s[j] - 'a'] == 1)
    			{
    
    				max = max>(j - i) ? max : (j - i);
    				break;
    			}
    			word[s[j] - 'a'] = 1;
    		}
    		if (j == m)
    		{
    			max = max>(j - i) ? max : (j - i);
    			break;
    		}
    	}
    	return (max);
    }};
    

    I have run the code in VS2013 and there is no error. But when I submitted it in this website, it showed "Runtime error". I don't know what is wrong. I would appreciate it very much if anyone can help me.


Log in to reply
 

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