139. Word Break
来源:互联网 发布:皇室战争恶搞卡牌软件 编辑:程序博客网 时间:2024/06/07 10:07
Given a string s and a dictionary of words dict, determine ifs 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"
.
分析:动态规划;
设置一个boolean数组,其中每个元素用来代表字符串s的前i个字符串,是不是能够用set中的字符串表示。
时间复杂度:O(N*N)
空间复杂度:O(N)
public class Solution { public boolean wordBreak(String s, Set<String> wordDict) { int n=s.length(); boolean[] flag=new boolean[n+1]; flag[0]=true; for(int i=1;i<=n;i++){ for(int j=0;j<=i;j++){ String temp=s.substring(j,i); if(flag[j]&&wordDict.contains(temp)){ flag[i]=true; } } } return flag[n]; }}
0 0
- LeetCode 139. Word Break
- 139.Word Break
- [LeetCode]139.Word Break
- 139. Word Break
- [leetcode] 139.Word Break
- leetcode 139. Word Break
- [LeetCode]139. Word Break
- 139. Word Break LeetCode
- 139. Word Break
- 139. Word Break
- LeetCode-139.Word Break
- LeetCode *** 139. Word Break
- LeetCode 139. Word Break
- 139. Word Break
- LeetCode 139. Word Break
- 139. Word Break
- 139. Word Break
- [leetcode] 139. Word Break
- it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping>
- 神经网络使用情景
- String.CopyTo
- 1077. Kuchiguse (20)解题报告
- Android关于Theme.AppCompat相关问题的深入分析
- 139. Word Break
- HttpURLConnection实现多线程下载
- int转 string
- 数据库学习笔记和小练习(6)sql查询和更新练习
- 面试专栏:算法与数据结构,虚拟机,Java基础,JavaWeb
- Swift 3.0 API设计准则
- EventBus 解析
- 在 CentOS7 上安装 zookeeper-3.4.9 服务
- JSP新闻系统之六 后台登陆页面