Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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;
}
Comment

PREVIOUS NEXT
Code Example
Java :: check java variable type using getSimpleName method 
Java :: how to set id to TextView programmatically java android 
Java :: java private access modifier 
Java :: How do you use both Spring Data JPA and Spring Data Elasticsearch repositories on the same domain class in a Spring Boot application? 
Java :: how to see if a shape is touching another shape in java 
Java :: android studio doesnt work when in full screen mac os 
Java :: list all android sensors in java 
Java :: before first method in jdbc 
Java :: java arduino 
Java :: merge sort algorithm in java short answer 
Java :: broswerCallback springboot and jms 
Java :: jks not found when trying googlenethttptransport 
Java :: how to find the maximum value of an attribute of an item in a stream java 
Java :: spigot item break 
Java :: set attribute java 
Java :: java program for wind-chill temperature 
Java :: masquer saisie mot de passe java console 
Java :: close scanner in while loop java 
Java :: binary search 2D java 
Java :: how can i press a key using action class i java ? 
Java :: ant bild skip java doc 
Java :: Which of the following is an example of a Method reference? 
Java :: index out of bounds exception java 
Java :: java create a hashmap 
Java :: google intent for directions 
Java :: forge close gui java 
Java :: correct lcd initialize 
Java :: newinstance in java giving exception 
Java :: java :: operator 
Java :: The JAVA_HOME environment variable is not defined correctly, this environment variable is needed to run this program. 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =