标签:key dict return bsp etc map res ret solution
class Solution { public boolean wordBreak(String s, List<String> wordDict) { return isContain(s, wordDict); } Map<String,Boolean> map = new HashMap<>(); public boolean isContain(String s, List<String> wordDict) { if (s.equals("")) return true; if (map.containsKey(s)) { return false; } boolean result = false; for (int i=0;i<s.length();i++) { String temp = s.substring(0, i+1); if (wordDict.contains(temp)) { result = result || isContain(s.substring(i+1), wordDict); if (!result) { map.put(s.substring(i+1), true); } } } return result; } }
标签:key dict return bsp etc map res ret solution
原文地址:https://www.cnblogs.com/juniorMa/p/14545195.html