private int calcCountSubstringsWords ( String str , HashSet < String > words ) { int wordCount = 0 ; int N = str . length ( ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) for ( int j = i + 2 ; j < N + 1 ; j ++ ) { if ( words . contains ( str . substring ( i , j ) ) ) wordCount += 1 ; } return wordCount ; }
count all substrings > = 2 chars that are in words