My AC answer in JAVA()


  • 0
    Q

    public class Solution {

    public Set<String> unmatch=new HashSet<String>();
    public boolean wordBreak(String s, Set<String> dict) {
        
        if(s.length()==0){
            return true;
        }
       int count=s.length();
         if (unmatch.contains(s)){
             return false;
         }
         for(int i=1;i<=count;i++){
             if(dict.contains(s.substring(0,i))&&wordBreak(s.substring(i,count),dict)){
                 return true;
             }
         }
         
        unmatch.add(s);    
         return false;
        
    }
    

    }


Log in to reply
 

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