일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Kafka
- Python
- 900gle
- token filter test
- zip 암호화
- TensorFlow
- MySQL
- Test
- sort
- Mac
- analyzer test
- plugin
- Java
- aggregation
- 파이썬
- springboot
- license delete
- License
- matplotlib
- docker
- aggs
- ELASTIC
- Elasticsearch
- 차트
- high level client
- query
- API
- flask
- licence delete curl
- zip 파일 암호화
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