Leetcode-word-break
来源:互联网 发布:英雄钢笔美工9018 编辑:程序博客网 时间:2024/06/07 01:52
题目描述
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".
运用动态规划的思路,dp[i]表示0-i长度的单词是否可分
import java.util.*;public class Solution { public boolean wordBreak(String s, Set<String> dict) { int n = s.length(); boolean[] dp = new boolean[n+1];dp[0] = true;for(int i=1; i<=n; i++){for(int j=0; j<i; j++){if(dp[j] && dict.contains(s.substring(j,i))){dp[i] = true;break;}}}return dp[n]; }}
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
- (C++)浅谈自增运算
- C语言标准库(了解)
- Runloop 详解
- LeetCode 284. Peeking Iterator
- Linuxtop性能分析命令
- Leetcode-word-break
- 比较时间格式是否相等的函数
- Java反转单链表(code)
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- Java Web开发框架对比—Part0—引言
- Android应用被强制停止后无法接受广播解决方案
- (C++)按位取反
- kernel 文档
- centos7之lamp环境搭建