Random commentary about Machine Learning, BigData, Spark, Deep Learning, C++, STL, Boost, Perl, Python, Algorithms, Problem Solving and Web Search
Nice problem!Set dict = new HashSet(); dict.add("coding"); dict.add("play"); dict.add("ground"); dict.add("playground"); dict.add("blog"); dict.add("spot"); String url = "codingplayground.blogspot.com"; List list = new ArrayList(); List tmp = new ArrayList(); for(int i = 0; i < url.length(); i++) { char ch = url.charAt(i); tmp.clear(); if (dict.contains("" + ch)) System.out.println(ch); for(String prev : list) { String word = prev + ch; if (dict.contains(word)) System.out.println(word); tmp.add(word); } list.clear(); list.addAll(tmp); list.add("" + ch); } }
Nice problem!
ReplyDeleteSet dict = new HashSet();
dict.add("coding");
dict.add("play");
dict.add("ground");
dict.add("playground");
dict.add("blog");
dict.add("spot");
String url = "codingplayground.blogspot.com";
List list = new ArrayList();
List tmp = new ArrayList();
for(int i = 0; i < url.length(); i++) {
char ch = url.charAt(i);
tmp.clear();
if (dict.contains("" + ch)) System.out.println(ch);
for(String prev : list) {
String word = prev + ch;
if (dict.contains(word)) System.out.println(word);
tmp.add(word);
}
list.clear();
list.addAll(tmp);
list.add("" + ch);
}
}