Time limit executed! Is there something wrong


  • 0
    S

    This solution goes well in my machine (using visual studio 2012), but submisstion is wrong,Time limit executed, Last executed input: "baxvcvuprixikpgckondravcyiurlgkoghkkeebypzizqpccdrfwtbaslvjxbwljfxvm"
    while run in my machine,it instantly exit with the return value 13, So I wonder is there something wrong in my solution which rely on platform or something else

    class Solution {
    public:
        int lengthOfLongestSubstring(string s) {
    		if(s.compare("")==0)
    			return 0;
            set<char> dict,subDict;
    		int length=s.size();
    		for(string::iterator it=s.begin();it!=s.end();it++)
    			dict.insert(*it);
    		int subLength=dict.size();
    		while(subLength!=0)
    		{
    			for(int i=0;i<length-subLength+1;i++)
    			{
    				subDict.clear();
    				string sub=s.substr(i,subLength);
    				for(string::iterator it=sub.begin();it!=sub.end();it++)
    					subDict.insert(*it);
    				if(subDict.size()==subLength)
    					return subLength;
    			}
    			subLength--;
    		}
    
        }
    };

Log in to reply
 

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