Lesson4 - MissingInteger

Correctness 100%
Performance 0%
Task score 55%
※for文回しすぎ
※要改善

作成日:2018/1/31
MissingInteger 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");

class Solution {
    public static int solution(int[] A) {

      int smallest = 1;
      int bigest = 0;

      int r = 0;
      int s = 0;

      for ( int num : A ) {
        if ( num > r ) { r = num; }
        if ( num < s ) { s = num; }
      }

      if ( r <= 0 ) { return smallest; }

      boolean[] flag = new boolean[r];

      for (int i = 0; i < flag.length; i++) {
        flag[i] = true;
      }

      for ( int num : A ) {
        for (int i = 1; i <= r; i++) {
          if ( num == i ) { flag[i-1] = false; }
        }
      }

      for (int i = 0; i < flag.length; i++) {
        if ( flag[i] == true ) {
          bigest = i + 1;
          break;
        }
      }

      if ( bigest == 0 ) { bigest = r + 1; }

      return bigest;
    }
}