find all possible substrings of a string java
for (int i = 0; i < A.length(); i++) {
for (int j = i+1; j <= A.length(); j++) {
System.out.println(A.substring(i,j));
}
}
find all possible substrings of a string java
for (int i = 0; i < A.length(); i++) {
for (int j = i+1; j <= A.length(); j++) {
System.out.println(A.substring(i,j));
}
}
Create all possible substrings of a string java
public int delete(String query, HashSet dictionary) {
Queue queue = new LinkedList();
Set queueElements = new HashSet();
queue.add(query);
queueElements.add(query);
while (!queue.isEmpty()) {
String s = queue.remove();
queueElements.remove(s);
if (dictionary.contains(s)) return query.length() - s.length();
for (int i = 0; i < s.length(); i++) { String sub = s.substring(0, i) + s.substring(i+1, s.length()); if (sub.length() > 0 && !queueElements.contains(sub)) {
// this for loop creates all possible substrings
queue.add(sub);
queueElements.add(sub);
}
}
}
return -1;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us