LeetCode 139 Word Break
2015-12-01 20:49
344 查看
题目描述
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”.
代码
[code] public static boolean wordBreak(String s, Set<String> wordDict) { boolean[] P = new boolean[s.length() + 1]; P[0] = true; for (int i = 0; i < s.length(); i++) { for (int j = 0; j <= i; j++) { if (P[j] && wordDict.contains(s.substring(j, i + 1))) { P[i + 1] = true; } } } return P[s.length()]; }
相关文章推荐
- Oracle 11g数据库的安装
- RANSAC算法详解
- IOS7 UITextField 隐藏自身软键盘、点击Return自动转到下个文本框、轻触背景隐藏软键盘
- OC多线程
- Leetcode #171 Excel Sheet Column Number
- 电子或通信领域当前的主流技术及其社会需求调查报告
- self.xxx 和 _xx 的区别
- 给只有 backgroundColor 属性的类设置背景图片
- Masonry使用总结
- UE4 Actor生命周期
- 非常简单的汇编翻译器
- [Android学习笔记八] 使用VideoView屏幕方向发生变化,视频方向自动切换
- How Do I Declare A Block in Objective-C? [备忘]
- java基础之Gui编程和反射
- 抛出和接收异常的顺序
- How Do I Declare A Block in Objective-C? [备忘]
- 抛出和接收异常的顺序
- linux中/etc与/var目录,各是什么意思?这两个目录下的文件有什么特点?
- linux0.11 内核启动代码分析(一)
- 【转】fatal error C1189: #error : missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS