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
|
// you can also use imports, for example:
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
if (A.length == 1 ) return A[0];
//[2,2,2,4,5,5,4]-> 2,2,2,4,4,5,5
int res= 0;
for (int i = 0; i < A.length-1; i++) {
if (A[i] == A[i+1]) {
i++;
}
else {
res = A[i];
break;
}
}
if (res == 0) res = A[A.length-1];
return res;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'Codility > JAVA' 카테고리의 다른 글
FlogJump (0) | 2020.02.16 |
---|---|
TapeEquilibrium (0) | 2020.02.15 |
Cyclic Rotation (0) | 2020.02.15 |
Binary Gap (0) | 2020.02.15 |