Codility – PermMissingElem 문제 풀이 (난이도 : 하)

Codility – PermMissingElem 문제 풀이 (난이도 : 하)

// you can also use imports, for example:
// import java.util.*;

// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");

class Solution {
    public int solution(int[] A) {
        // write your code in Java SE 8
        
        boolean occurred[] = new boolean[A.length + 2];
        
        for(int i = 0 ; i < A.length ; i++){
            int occurredNumber = A[i];
            occurred[occurredNumber] = true;
        }
        
        for(int i = 1 ; i < occurred.length ; i++){
            if(!occurred[i]){
                return i;
            }
        }
        
        return 0;
    }
}
2264 Total Views 3 Views Today