标签:leetcode
https://oj.leetcode.com/problems/word-break/
http://blog.csdn.net/linhuanmars/article/details/22358863
public class Solution { public boolean wordBreak(String s, Set<String> dict) { s = "#" + s; // Add a dummy char int len = s.length(); boolean[] poss = new boolean[len]; poss[0] = true; for (int i = 1 ; i < len ; i ++) { for (int k = 0 ; k < i ; k ++) { poss[i] = poss[k] && dict.contains(s.substring(k + 1, i + 1)); if (poss[i]) break; } } return poss[len - 1]; } }
标签:leetcode
原文地址:http://7371901.blog.51cto.com/7361901/1600784