public boolean wordBreak(String s, Set<String> dict) {
          if(s.length()==0) return true;
          boolean[] res = new boolean[s.length()];
          
          for(int i=0; i<s.length(); i++)
          {
        	  for(String d:dict)
              {
            	  if(i >= d.length()-1 && s.substring(i-d.length()+1, i+1).equals(d))
            	  {
            		  res[i] = i-d.length()<0? true:res[i-d.length()];
            		  if(res[i]==true) break;
            	  }
           
              } 
          }
    	  return res[s.length()-1];
      }