原题地址

与Word Break II(参见这篇文章)相比,只需要判断是否可行,不需要构造解,简单一些。

依然是动态规划。

代码:

 bool wordBreak(string s, unordered_set<string> &dict) {
int maxLen = ;
for (auto w : dict)
maxLen = maxLen > w.length() ? maxLen : w.length(); vector<bool> res(s.length() + , false);
res[s.length()] = true; for (int i = s.length() - ; i >= ; i--) {
for (int l = ; !res[i] && l <= maxLen && i + l <= s.length(); l++)
res[i] = dict.find(s.substr(i, l)) != dict.end() && res[i + l];
} return res[];
}

Leetcode#139 Word Break的更多相关文章

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

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

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

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

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

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

  4. leetcode 139. Word Break ----- java

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

  5. LeetCode #139. Word Break C#

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

  6. [leetcode]139. Word Break单词能否拆分

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

  7. [LeetCode] 139 Word Break(BFS统计层数的方法)

    原题地址: https://leetcode.com/problems/word-break/description/ 题目: Given a non-empty string s and a dic ...

  8. [LeetCode] 139. Word Break 拆分词句

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

  9. Java for 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. mariadb介绍

    事务(Transaction):组织多个操作为一个整体,要么全部执行,要么全部不执行 “回滚” ,rollback SQL接口:sql语句分析器和优化器 表:为了满足范式设计要求,将一个数据集分拆为多 ...

  2. Hadoop在win7下部署的问题

    问题: 为了测试方便所以在win7下部署了伪分布式hadoop运行环境,但是部署结束后在命令行运行hadoop命令创建一个用户文件目录时出现了一下情况: 系统找不到指定的批标签- make_comma ...

  3. Creating an API-Centric Web Application[转]

    Creating an API-Centric Web Application 转自 http://hub.tutsplus.com/tutorials/creating-an-api-centric ...

  4. Service(一)----->简单计算

    xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...

  5. jQuery基础知识— 获得内容和属性

    jQuery拥有可操作HTML元素和属性的方法. 获得内容: text()--设置或返回所选元素的文本内容 html()--设置或返回所选元素的内容(包括HTML标记) val()--设置或返回表单字 ...

  6. ubuntu打开 txt 文件乱码

    ubuntu12.04 gedit 打开 windows 分区中的 txt 文件乱码,是因为 ubuntu 和 windows 两个系统的编码不同.解决办法:终端里依次输入以下2 条命令即可: 代码: ...

  7. HOOK API 在多线程时应该注意的问题点

    在使用INLINE HOOK API实现对系统API的拦截时,正常情况下并没有太大问题,但一旦涉及到多线程,不管是修改IAT还是JMP,2种方法均会出现不可预料的问题,特别是在HOOK一些复杂的大型系 ...

  8. 倒水问题 (codevs 1226) 题解

    [问题描述] 有两个无刻度标志的水壶,分别可装x升和y升 ( x,y 为整数且均不大于100)的水.设另有一水缸,可用来向水壶灌水或接从水壶中倒出的水, 两水壶间,水也可以相互倾倒.已知x升壶为空壶, ...

  9. 【转载!】关于C#的RawSocket编程的问题

    Q:你好! 看过了你在csdn上发表的<用C#下的Raw Socket编程实现网络封包监视>,觉得很感兴趣,而且对我的帮助很大.不过在调试的过程中遇到一些问题,特此向你请教一下.谢谢! 首 ...

  10. 【J2EE】Java连接SQL Server 2000问题:“com.microsoft.sqlserver.jdbc.SQLServerException:用户'sa'登录失败。该用户与可信SQL Server连接无关联”

    1.问题现象 E:\JSP\HibernateDemo\HibernateDemoProject\src\sine>java ConnectSQLServerConnect failed!com ...