Word Break----leetcode
来源:互联网 发布:ssh指定端口 编辑:程序博客网 时间:2024/06/04 08:19
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"
.
题目大意:很浅显,这里不解释了,采用官网上的动态规划的解法,注意可能会出现数组越界,区别c++中的substr(pos,len)和java中的substring(beginIndex,endIndex),参数:beginIndex:开始处的索引(包括),endIndex :结束处的索引(不包括)。代码如下:
public class Solution { public boolean wordBreak(String s, Set<String> dict) { if(dict.isEmpty()) { return false; } if(s.length()==0) return true; int length; length=s.length(); boolean[] wordB=new boolean[length+1]; wordB[0]=true; for(int i=1;i<=length;i++) for(int j=0;j<i;j++) { if(wordB[j]&&dict.contains(s.substring(j,i))) { wordB[i]=true; break; } } return wordB[length]; }}
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
- 利用VB设计打印复杂报表——OFFICE里面的一些小技巧
- 开启oracle的flashback闪回功能
- 博弈 hdu 3032 、hdu 1525
- struts2 提交表单后,不走action中的方法,直接返回input
- MySQL导出表字段和数据xls
- Word Break----leetcode
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- MYSQL常用命令
- 数据库操作时,速度慢的解决方案
- android 自定义Toast显示风格
- 【原创】Ubuntu 下使用 ssmtp 向 gmal 发送邮件
- iOS 开放必备网址
- Nginx+PHP-FPM的域Socket配置方法
- HDU 1087 Super Jumping! Jumping! Jumping!