[Leetcode] Word Break
来源:互联网 发布:java设计小游戏 编辑:程序博客网 时间:2024/06/05 14:38
public class Solution { Map<String, Boolean> record; public Solution() { record = new HashMap<>(); } public boolean wordBreak(String s, Set<String> wordDict) { if(s.equals("")) return true; if(record.get(s) == null){ for(int i = 0; i < s.length(); i++) { String subString = s.substring(0, i+1); if(wordDict.contains(subString)) { if(wordBreak(s.substring(i+1), wordDict)) { record.put(s, Boolean.TRUE); return Boolean.TRUE; } } else { continue; } } record.put(s, Boolean.FALSE); return false; } else{ return record.get(s); } }}
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
For example, given
s = "leetcode"
,
dict = ["leet", "code"]
.
Return true because "leetcode"
can be segmented as "leet code"
.
0 0
- leetcode Word Break & Word Break ||
- Leetcode: Word Break
- [leetcode]Word Break
- [leetcode]Word Break II
- LeetCode:Word Break
- LeetCode:Word Break II
- Leetcode: Word Break II
- [LeetCode] Word Break
- [LeetCode] Word Break II
- LeetCode: Word Break
- leetcode之Word Break
- [LeetCode]Word Break II
- [LeetCode]Word Break
- leetcode-Word Break
- LeetCode 之 Word Break
- leetcode word break
- LeetCode | Word Break
- LeetCode | Word Break II
- js对节点的操作,添加,删除,获得父节点,子节点,兄弟节点
- django admin 报错没有发现 table
- Handler消息传递机制
- LeetCode 题解(242) : Palindrome Permutation II
- Binary Search
- [Leetcode] Word Break
- 晶联讯1353显示屏测试程序
- Python 之包(Package)与模(Module)
- Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.
- Linux上安装MySQL时出现不兼容的解决办法
- LeetCode 题解(243) : Paint Fence
- LeetCode 题解(244) : Missing Ranges
- Node.js开发入门—语音合成示例
- unity官方demo学习之Stealth(六)CCTV监控摄像机