Skip to content

Commit 987ea21

Browse files
author
Alfredo Miranda
committed
Modified maxMirror.java
1 parent 496292a commit 987ea21

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

java/array-3/maxMirror.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,20 @@ public int maxMirror(int[] nums) {
88
int max = 0;
99

1010
for(int start = 0; start < nums.length; start++) {
11-
int begin = nums.length - 1;
12-
13-
while(begin >= 0) {
14-
int finish = start + 1;
15-
while(begin >= 0 && nums[begin] != nums[start])
16-
begin--;
17-
18-
int end = begin - 1;
19-
20-
while(finish < nums.length && end >= 0 &&
21-
nums[finish] == nums[end]) {
22-
finish++;
23-
end--;
11+
for(int begin = nums.length - 1; begin >= 0; begin--) {
12+
int size = 0;
13+
int i = start;
14+
int j = begin;
15+
16+
while(i < nums.length && j >= 0 && nums[i] == nums[j]) {
17+
size++;
18+
i++;
19+
j--;
2420
}
25-
26-
max = Math.max(max, finish - start);
27-
28-
begin--;
21+
22+
max = Math.max(max, size);
2923
}
3024
}
31-
25+
3226
return max;
3327
}

0 commit comments

Comments
 (0)