We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7c527ec commit 8539449Copy full SHA for 8539449
DynamicProgramming/WordBreakProblem/WordBreakPrintWords.java
@@ -0,0 +1,19 @@
1
+/*
2
+https://www.techiedelight.com/word-break-problem/
3
+https://www.geeksforgeeks.org/word-break-problem-using-backtracking/?ref=rp
4
+*/
5
+
6
+public void printWordBreak(String s, Set<String> dict, String res){
7
+ if(s.length() == 0){
8
+ System.out.println(res);
9
+ return;
10
+ }
11
12
+ for(int i=1;i<=s.length();i++){
13
+ String prefix = s.substring(0,i);
14
15
+ if(dict.contains(prefix)){
16
+ printWordBreak(s.substring(i), dict, res+" "+prefix);
17
18
19
+}
0 commit comments