Skip to content

Commit 8153e55

Browse files
committed
Fixed sonar
1 parent 52b0217 commit 8153e55

File tree

1 file changed

+6
-8
lines changed
  • src/main/java/g3201_3300/s3245_alternating_groups_iii

1 file changed

+6
-8
lines changed

src/main/java/g3201_3300/s3245_alternating_groups_iii/Solution.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,12 @@ private int processQueryType1(int[] colors, TreeMap<Integer, Integer> groups, in
101101
Map.Entry<Integer, Integer> lastGroup = groups.lastEntry();
102102
// If there is more than one group and the first and last colors differ,
103103
// adjust the answer by "merging" the groups at the boundaries.
104-
if (firstGroup != lastGroup) {
105-
if (colors[0] != colors[colors.length - 1]) {
106-
int leftLen = len(firstGroup.getKey(), firstGroup.getValue());
107-
int rightLen = len(lastGroup.getKey(), lastGroup.getValue());
108-
ans -= Math.max(leftLen - groupSize + 1, 0);
109-
ans -= Math.max(rightLen - groupSize + 1, 0);
110-
ans += Math.max(leftLen + rightLen - groupSize + 1, 0);
111-
}
104+
if (firstGroup != lastGroup && colors[0] != colors[colors.length - 1]) {
105+
int leftLen = len(firstGroup.getKey(), firstGroup.getValue());
106+
int rightLen = len(lastGroup.getKey(), lastGroup.getValue());
107+
ans -= Math.max(leftLen - groupSize + 1, 0);
108+
ans -= Math.max(rightLen - groupSize + 1, 0);
109+
ans += Math.max(leftLen + rightLen - groupSize + 1, 0);
112110
}
113111
return ans;
114112
}

0 commit comments

Comments
 (0)