Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 11th, 2018 63 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. class Solution {
  2.     public int solution(int[] A) {
  3.         int counter[] = new int[A.length];
  4.    
  5.         // Count the items, only the positive numbers
  6.         for (int i = 0; i < A.length; i++)
  7.             if (A[i] > 0 && A[i] <= A.length)
  8.                 counter[A[i] - 1]++;
  9.        
  10.         // Return the first number that has count 0
  11.         for (int i = 0; i < counter.length; i++)
  12.             if (counter[i] == 0)
  13.                 return i + 1;
  14.        
  15.         // If no number has count 0, then that means all number in the sequence
  16.         // appears so the next number not appearing is in next number after the
  17.         // sequence.
  18.         return A.length + 1;
  19.     }
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top