일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 파이썬
- TensorFlow
- Test
- 900gle
- Java
- flask
- License
- query
- springboot
- docker
- Mac
- license delete
- analyzer test
- licence delete curl
- Elasticsearch
- MySQL
- aggs
- Python
- high level client
- zip 암호화
- zip 파일 암호화
- API
- ELASTIC
- plugin
- 차트
- Kafka
- token filter test
- matplotlib
- sort
- aggregation
Archives
- Today
- Total
개발잡부
코딜리티 10 본문
반응형
This is a demo task.
Write a function:
class Solution { public int solution(int[] A); }
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
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 [−1,000,000..1,000,000].
public static int solution(int[] A) {
// write your code in Java SE 8
Set<Integer> set = new HashSet<>();
for (int a : A) {
set.add(a);
}
int i = 1;
while (true) {
if (!set.contains(i)) {
return i;
}
i++;
}
}
반응형
Comments