注意:不一定是一分为2
1 package leetcode; 2 3 import java.util.Set; 4 5 public class WordBreak11 { 6 public boolean wordBreak(String s, Set<String> dict) { 7 if(s==null||s.length()==0||dict==null||dict.size()==0){ 8 return false; 9 } 10 int len = s.length(); 11 boolean[] can=new boolean[len+1]; 12 can[0]=true; 13 for(int i=1;i<=len;i++){ 14 for(int j=0;j<i;j++){ 15 if(can[j]&&dict.contains(s.substring(j,i))){ 16 can[i]=true; 17 break; 18 } 19 } 20 } 21 return can[len]; 22 } 23 }
leetcode--007 word break I,布布扣,bubuko.com
原文:http://www.cnblogs.com/thehappyyouth/p/3880637.html