Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- ObjectOutputStream
- 반응형 웹 프로젝트
- CSS
- 사전학습
- 예제
- FFT
- GridLayout
- html 기초
- FileWriter
- css 기초
- g검정
- BorderLayout
- Database
- HTML
- 파이썬
- html 프로젝트
- oracle
- iframe 태그
- rnn
- java
- 반응형웹
- inline
- FlowLayout
- 푸리에 변환
- Codility
- 미디어쿼리
- 메서드
- Position
- 상속
- 퍼셉트론
Archives
- Today
- Total
도라에몽주머니
[Codility/Java] 문제 5. PermMissingElem 본문

Task
An array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing.
Your goal is to find that missing element.
Write a function:
class Solution { public int solution(int[] A); }
that, given an array A, returns the value of the missing element.
For example, given array A such that:
A[0] = 2 A[1] = 3 A[2] = 1 A[3] = 5
the function should return 4, as it is the missing element.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [0..100,000];
- the elements of A are all distinct;
- each element of array A is an integer within the range [1..(N + 1)].
Solution
import java.util.*;
class Solution {
public int solution(int[] A) {
Arrays.sort(A);
for(int i=0; i<A.length; i++) {
if(A[i] != i+1) return i+1;
}
return A.length + 1;
}
}'Algorithm' 카테고리의 다른 글
| [Codility/Java] 문제 6. TapeEquilibrium (0) | 2022.12.06 |
|---|---|
| [Codility/Java] 문제 4. FrogJmp (0) | 2022.11.22 |
| [Codility/Java] 문제 3. OddOccurrencesInArray (0) | 2022.11.22 |
| [Codility/Java] 문제 2. CyclicRotation (0) | 2022.11.17 |
| [Codility/Java] 문제 1. BinaryGap (0) | 2022.11.04 |