LeetCode/string/DistinctEchoSubstrings.java
// Hint #3 Try all substrings and use hashing to check them.
Hint #3 Try all substrings and use hashing to check them.
Hint #3 Try all substrings and use hashing to check them .
public int distinctEchoSubstrings(String text) {
        Set<String> entry = new HashSet<>();
        Set<String> valid = new HashSet<>();
        String temp;
        for (int i = 0; i < text.length(); i++) {
            for (int j = i; j < text.length(); j++) {
                temp = text.substring(i, j);
                if (!entry.contains(temp)) {
                    entry.add(temp);
                    if (text.contains(temp + temp)) {
                        valid.add(temp);
                    }
                }
            }
        }
        valid.remove("");
        System.out.println(valid.size());
        return valid.size();
    }
public int distinctEchoSubstrings ( String text ) { Set < String > entry = new HashSet < > ( ) ; Set < String > valid = new HashSet < > ( ) ; String temp ; for ( int i = 0 ; i < text . length ( ) ; i ++ ) { for ( int j = i ; j < text . length ( ) ; j ++ ) { temp = text . substring ( i , j ) ; if ( ! entry . contains ( temp ) ) { entry . add ( temp ) ; if ( text . contains ( temp + temp ) ) { valid . add ( temp ) ; } } } } valid . remove ( "" ) ; System . out . println ( valid . size ( ) ) ; return valid . size ( ) ; }
Hint #3 Try all substrings and use hashing to check them.
Hint #3 Try all substrings and use hashing to check them .
// #1 get all the substring "a" of text // #2 get the echo string of "a" --> "a + a " // #3 to see if "a + a " is a substring of text