Is my solution correct? The submission result turned out to be" Time Limit Exceeded"


  • 0
    E

    code as below:

    class Solution {
        public List<Integer> findSubstring(String s, String[] words) {
           List<Integer>list=new ArrayList<Integer>();int k=0;
           int len=words[0].length();int Len=len*words.length;
           for(int i=0;i<=s.length()-Len;i++)
           {List<String> list2=new ArrayList<String>(Arrays.asList(words));
        	   while(list2.contains(s.substring(i, i+len)))
        	   {list2.remove(s.substring(i,i+len));k=k+len;i=i+len;
           if(k==Len) {list.add(i-Len);break;}
          
        	   }
        	   
        	   if(k!=0) {i=i-k;k=0;}
        	   
           }
           return list;
        }
    }

Log in to reply
 

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