-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
34 lines (34 loc) · 916 Bytes
/
Solution.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
30
31
32
33
34
class Solution {
int solution(int[] A) {
int n = A.length;
int result = 0;
for (int i = 0; i < n - 1; i++) {
if (A[i] == A[i + 1])
result = result + 1;
}
int r = 0;
for (int i = 0; i < n; i++) {
int count = 0;
if (i > 0) {
if (A[i - 1] != A[i])
count = count + 1;
else
count = count - 1;
}
if (i < n - 1) {
if (A[i + 1] != A[i])
count = count + 1;
else
count = count - 1;
}
r = Math.max(r, count);
System.out.println(r);
}
return result + r;
}
public static void main(String[] args) {
int a[] = {1,1,1,0,1,0};
Solution s = new Solution();
System.out.println(s.solution(a));
}
}