How can I improve my Code


  • 0
    J
    public class Solution {
    public List<Integer> findSubstring(String s, String[] words) {
       
        List<Integer> result= new ArrayList<>();
        int totalLength=0;
        for(String a:words)
        totalLength+=a.length();
        
        HashSet<String> dict = new HashSet<String>(); 
        for(int i=0;i<s.length()-totalLength;i++)
        {
            String temp=s.substring(i,i+totalLength);
            int j=0;
           
            while(j<words.length)
            {
                if(temp.indexOf(words[j])>=0)
                {
                    dict.add(words[j]);
                    j++;
                }
                else
                break;
                
            }
            if(dict.size()==words.length)
            result.add(i);
            dict.clear();
        }
        return result;
        
        
        
    }
    

    }


Log in to reply
 

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