Lesson3 - PermMissingElem

作成日:2018/3/15
PermMissingElem coding task - Learn to Code - Codility

// 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");

import java.util.HashMap;
class Solution {
    public static int solution(int[] A) {
        // write your code in Java SE 8

        HashMap<Integer,Boolean> hash = new HashMap<Integer,Boolean>();
        int i = 0;

        for(i = 0; i <= A.length + 1; i++) {  // 0 ~ 5
            try {
                hash.put(A[i], true);
            } catch(Exception ex) {
            }
        }

        while (i-- != 1) {
          if(!hash.containsKey(i)) {
                return i;
          }
        }

        return 0;
    }
}