We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 496292a commit 987ea21Copy full SHA for 987ea21
java/array-3/maxMirror.java
@@ -8,26 +8,20 @@ public int maxMirror(int[] nums) {
8
int max = 0;
9
10
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--;
+ for(int begin = nums.length - 1; begin >= 0; begin--) {
+ int size = 0;
+ int i = start;
+ int j = begin;
+
+ while(i < nums.length && j >= 0 && nums[i] == nums[j]) {
+ size++;
+ i++;
+ j--;
24
}
25
26
- max = Math.max(max, finish - start);
27
28
+ max = Math.max(max, size);
29
30
31
32
return max;
33
0 commit comments