GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaInterview/java/src/LeetCode/WordBreak_139.java at master · damaohongtu/JavaInterview

Expand file tree

/

WordBreak_139.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
38 lines (34 loc) · 999 Bytes
/

WordBreak_139.java

Copy path

File metadata and controls

38 lines (34 loc) · 999 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package LeetCode;
import java.util.ArrayList;
import java.util.List;
/**
* @Classname WordBreak_139
* @Description 切分字符串,要刚刚好切分为字典中的单词
* 解法:
* @Date 19-5-10 下午11:01
* @Created by mao<[email protected]>
*/
public class WordBreak_139 {
public static boolean wordBreak(String s, List<String> wordDict) {
int len=s.length()+1;
boolean[] flags=new boolean[len];
flags[0]=true;
for(int i=1;i<len;i++){
for(int j=i-1;j>=0;j--){
if(flags[j]&&wordDict.contains(s.substring(j,i))){
flags[i]=true;
break;
}
}
}
return flags[len-1];
}
public static void main(String[] args){
List<String> wordDict=new ArrayList<>();
wordDict.add("leet");
wordDict.add("code");
String s="leetcode";
boolean result=wordBreak(s,wordDict);
System.out.print(result);
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.