forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2078.java
29 lines (28 loc) · 809 Bytes
/
_2078.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.fishercoder.solutions;
public class _2078 {
public static class Solution1 {
public int maxDistance(int[] colors) {
int left = 0;
int right = colors.length - 1;
int max = 0;
while (left < right) {
if (colors[left] != colors[right]) {
max = Math.max(max, right - left);
break;
} else {
left++;
}
}
left = 0;
while (left < right) {
if (colors[left] != colors[right]) {
max = Math.max(max, right - left);
break;
} else {
right--;
}
}
return max;
}
}
}