题目链接:https://leetcode-cn.com/problems/word-break/

参考链接:https://blog.csdn.net/c_flybird/article/details/80703494

     http://www.cnblogs.com/springfor/p/3874731.html

这种题目一般出现字符串、子数组都需要使用动态规划

dp[i],前i个字符串是否在字典中。

dp[0]=true;空字符肯定是在字典中。

public boolean wordBreak(String s, List<String> wordDict) {
boolean dp[]=new boolean[s.length()+1];
Arrays.fill(dp, false);
dp[0]=true;
for (int i = 1; i < dp.length; i++) {
for (int j = i - 1; j >= 0; j--)
{
if (dp[j] && wordDict.contains(s.substring(j, i)))
{
dp[i] = true;
break;
}
} }
return dp[s.length()];
}

动态规划之139 Word Break的更多相关文章

  1. leetcode 139. Word Break 、140. Word Break II

    139. Word Break 字符串能否通过划分成词典中的一个或多个单词. 使用动态规划,dp[i]表示当前以第i个位置(在字符串中实际上是i-1)结尾的字符串能否划分成词典中的单词. j表示的是以 ...

  2. 139. Word Break 以及 140.Word Break II

    139. Word Break Given a non-empty string s and a dictionary wordDict containing a list of non-empty  ...

  3. Leetcode#139 Word Break

    原题地址 与Word Break II(参见这篇文章)相比,只需要判断是否可行,不需要构造解,简单一些. 依然是动态规划. 代码: bool wordBreak(string s, unordered ...

  4. 139. Word Break

    题目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-se ...

  5. [LeetCode] 139. Word Break 单词拆分

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine ...

  6. 【LeetCode】139. Word Break 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  7. 139. Word Break(动态规划)

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine ...

  8. LeetCode 139. Word Break单词拆分 (C++)

    题目: Given a non-empty string s and a dictionary wordDict containing a list of non-emptywords, determ ...

  9. 【LeetCode】139 - Word Break

    Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...

随机推荐

  1. AM自动化测试平台

    AM自动化测试平台介绍: 最初目标:是为了做接口自动化测试,该平台,集成了,用例管理,测试执行,测试套件(主要为了应对,对场景业务流程有需要的),测试报告展示. 后期目标:适当增加,其它测试工具进行集 ...

  2. template.js简单入门

    template.js是一款开源的JavaScript模板引擎,用来渲染页面的. github地址 https://github.com/yanhaijing/template.js 下载templa ...

  3. gitlab RPM卸载 & 安装 && 升级(9.0.13-》9.5.9-》10.0->10.3.9->10.6.6-》10.8-》11.0)

    版本:9.0.3 升级版本:9.0.13 一,停止服务 gitlab-ctl stop unicorn gitlab-ctl stop sidekiq gitlab-ctl stop nginx 二, ...

  4. apc

    转载(https://www.kancloud.cn/thinkphp/php-best-practices/40866) 使用 APC 在一个标准的 PHP 环境中,每次访问PHP脚本时,脚本都会被 ...

  5. python遍历某一位置所有文件夹中的文件

    通过多次遍历达到找出所有文件的目的 import os rootdir=["d:/77"] c=[] for i in rootdir: for parent,dirnames,f ...

  6. IoC, DI,Spring.net

    IoC : Inversion of Control , 控制反转,就是创建对象(实例)的权利由开发人员自己控制New转到了由容器来控制.实现了解耦. DI: Dependency Injection ...

  7. Spring 默认的 AopProxy

    Spring 默认的 AopProxy JdkDynamicAopProxy Spring xml 文件默认解析器 DefaultDocumentLoader 采用 standard JAXP-con ...

  8. 什么是 shell

     shell 在计算机科学中,Shell俗称壳(用来区别于核),是指“为使用者提供操作界面”的软件(命令解析器).它类似于DOS下的command.com和后来的cmd.exe.它接收用户命令,然后调 ...

  9. 常用正则表达式爬取网页信息及HTML分析总结

    Python爬取网页信息时,经常使用的正则表达式及方法. 1.获取<tr></tr>标签之间内容 2.获取<a href..></a>超链接之间内容 3 ...

  10. python PIL 图像处理操作

    python PIL 图像处理 # 导入Image库 import Image # 读取图片 im = Image.open("1234.jpg") # 显示图片 im.show( ...