일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- springboot
- licence delete curl
- Elasticsearch
- 900gle
- flask
- Kafka
- docker
- License
- license delete
- 차트
- analyzer test
- high level client
- 파이썬
- TensorFlow
- Test
- plugin
- API
- MySQL
- sort
- Mac
- matplotlib
- Python
- token filter test
- query
- ELASTIC
- aggs
- aggregation
- zip 파일 암호화
- zip 암호화
- Java
Archives
- Today
- Total
개발잡부
[codility] NumberOfDiscIntersections 본문
반응형
public static int solution(int[] A) {
// write your code in Java SE 8
int N = A.length;
long[] lower = new long[N];
long[] upper = new long[N];
for (int i = 0; i < N; i++) {
lower[i] = i - (long) A[i];
upper[i] = i + (long) A[i];
}
Arrays.sort(lower);
Arrays.sort(upper);
int intersection = 0;
int j = 0;
for (int i = 0; i < N; i++) {
while (j < N && upper[i] >= lower[j]) {
intersection += j;
intersection -= i;
j++;
}
}
if (intersection > 10000000) return -1;
return intersection;
}
반응형
'이직' 카테고리의 다른 글
[codility] Nesting (0) | 2022.07.26 |
---|---|
[codility] Brackets (0) | 2022.07.25 |
[codility] Triangle (0) | 2022.07.25 |
[codility] MaxProductOfThree (0) | 2022.07.25 |
[codility] Distinct (0) | 2022.07.24 |
Comments