일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 차트
- flask
- matplotlib
- Elasticsearch
- Test
- Kafka
- aggregation
- licence delete curl
- analyzer test
- MySQL
- sort
- ELASTIC
- license delete
- aggs
- zip 파일 암호화
- query
- API
- Mac
- token filter test
- high level client
- 900gle
- License
- Java
- TensorFlow
- Python
- 파이썬
- zip 암호화
- springboot
- docker
- plugin
Archives
- Today
- Total
개발잡부
[codility] AbsDistinct 본문
반응형
A non-empty array A consisting of N numbers is given. The array is sorted in non-decreasing order. The absolute distinct count of this array is the number of distinct absolute values among the elements of the array.
For example, consider array A such that:
A[0] = -5
A[1] = -3
A[2] = -1
A[3] = 0
A[4] = 3
A[5] = 6
The absolute distinct count of this array is 5, because there are 5 distinct absolute values among the elements of this array, namely 0, 1, 3, 5 and 6.
Write a function:
class Solution { public int solution(int[] A); }
that, given a non-empty array A consisting of N numbers, returns absolute distinct count of array A.
For example, given array A such that:
A[0] = -5
A[1] = -3
A[2] = -1
A[3] = 0
A[4] = 3
A[5] = 6
the function should return 5, as explained above.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000];
each element of array A is an integer within the range [−2,147,483,648..2,147,483,647];
array A is sorted in non-decreasing order.
Copyright 2009–2023 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
문제안에 답이있는..
절대값 중복제거
Math.abs 가 절대값이고 Set 으로 중복제거를 했더니 통과..
easy 는 easy 인데..
public static int solution(int[] A) {
int ret = 0;
Set<Integer> set = new HashSet<>();
for (int aa : A){
set.add(Math.abs(aa));
}
ret = set.size();
return ret;
}
반응형
'이직 > codility' 카테고리의 다른 글
[codilty] MaxProfit (0) | 2023.05.16 |
---|---|
[codility] Fish (0) | 2022.07.26 |
[codility_] PermMissingElem (0) | 2022.07.23 |
Comments