题目链接: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. Request.UrlReferrer注意点

    定义: public sealed class HttpRequest { // // 摘要: // 获取有关客户端上次请求的 URL 的信息,该请求链接到当前的 URL. // // 返回结果: / ...

  2. System.ArgumentException: 目标数组的长度不够。请检查 destIndex 和长度以及数组的下限

    扫码支付接口将要上线,近几天在优化系统性能.昨天把日志Helper类的日志记录改成了使用Queue<T>对象来实现异步处理.做了单元测试,并模拟多线程来测试后,发现正常.今天将站点部署到准 ...

  3. vue中axios的封装

    第一步还是先下载axios cnpm install axios -S 第二步建立一个htttp.js import axios from 'axios'; import { Message } fr ...

  4. 从PHP官方镜像创建开发镜像

    https://xlange.com/post/dockerfile-baseon-official-php-image.html

  5. report源码分析——report_handle和report_server和report_catcher

    report_handle主要实现对message的action,severity,file的设置,然后将message传递给server: 主要的function有两个:initial和proces ...

  6. 学习笔记<2>Android基本四大组件

    <1>Activity(活动) ------与用户交互的界面 (1)Activity启动基本流程 <2>service(服务) <3>ContentProvider ...

  7. 检索系统向量化计算query-doc相似度

    def cal_sim2(A,B): ''' A :query [1,2] B: answers [[1,2],[3,5]] ''' need_norm=False A = np.array(A) B ...

  8. Must Know Tips/Tricks in Deep Neural Networks (by Xiu-Shen Wei)

    http://lamda.nju.edu.cn/weixs/project/CNNTricks/CNNTricks.html Deep Neural Networks, especially Conv ...

  9. 概念、DW介绍

    网页设计知识点大致分为五个部分,分别是: 1.概念.DW介绍: 2.标签: 3.样式表CSS: 4.JQuery: 5.JavaScript 概念.DW介绍: 一.网页的基本结构 <!--文档声 ...

  10. [openjudge-搜索]Lake Counting(翻译及实现)

    题目原文 描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is rep ...