Skip to content

Commit 5914143

Browse files
committed
refactor : 불필요한 연산 및 변수 수정
1 parent 45d659e commit 5914143

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/main/java/com/goorm/week2/yeji/Solution.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,25 @@ static int calculateScore(String s, int n) {
3131

3232
List<String> arrayList = new ArrayList<>();
3333
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));
3635
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));
4138
}
4239
}
4340

44-
List<String> sortedArray = arrayList.stream().distinct().sorted().toList();
41+
List<String> sortedUniqueSubStrings = arrayList.stream().distinct().sorted().toList();
4542
int max = 0;
4643
for (int i = 1; i < n - 1; i++) {
4744
String first = s.substring(0, i);
4845
for (int j = i + 1; j < n; j++) {
4946
String second = s.substring(i, j);
5047
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);
5350
}
5451
}
5552

56-
return max;
53+
return max + 3;
5754
}
5855
}

0 commit comments

Comments
 (0)