@@ -31,28 +31,25 @@ static int calculateScore(String s, int n) {
31
31
32
32
List <String > arrayList = new ArrayList <>();
33
33
for (int i = 1 ; i < n - 1 ; i ++) {
34
- String first = s .substring (0 , i );
35
- arrayList .add (first );
34
+ arrayList .add (s .substring (0 , i ));
36
35
for (int j = i + 1 ; j < n ; j ++) {
37
- String second = s .substring (i , j );
38
- String third = s .substring (j );
39
- arrayList .add (second );
40
- arrayList .add (third );
36
+ arrayList .add (s .substring (i , j ));
37
+ arrayList .add (s .substring (j ));
41
38
}
42
39
}
43
40
44
- List <String > sortedArray = arrayList .stream ().distinct ().sorted ().toList ();
41
+ List <String > sortedUniqueSubStrings = arrayList .stream ().distinct ().sorted ().toList ();
45
42
int max = 0 ;
46
43
for (int i = 1 ; i < n - 1 ; i ++) {
47
44
String first = s .substring (0 , i );
48
45
for (int j = i + 1 ; j < n ; j ++) {
49
46
String second = s .substring (i , j );
50
47
String third = s .substring (j );
51
- int compare = sortedArray .indexOf (first ) + sortedArray .indexOf (second ) + sortedArray .indexOf (third );
52
- max = Math .max (max , compare + 3 );
48
+ int compare = sortedUniqueSubStrings .indexOf (first ) + sortedUniqueSubStrings .indexOf (second ) + sortedUniqueSubStrings .indexOf (third );
49
+ max = Math .max (max , compare );
53
50
}
54
51
}
55
52
56
- return max ;
53
+ return max + 3 ;
57
54
}
58
55
}
0 commit comments