Advertisement
ffpaladin

Missing Int

Sep 30th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.awt.List;
  2. import java.util.ArrayList;
  3.  
  4. public class MissingInt {
  5.  
  6.     public static void main(String args[]){
  7.         ArrayList<Integer> list = new ArrayList <> ();
  8.        
  9.         list.add(1);
  10. //      list.add(2);
  11. //      list.add(3);
  12. //      list.add(4);
  13. //      list.add(6);
  14. //      list.add(7);
  15.        
  16.         // 1 2 3 4 6 7
  17.         // 1 1 1 1 1 1
  18.         // 1
  19.        
  20.         System.out.println(missingInt(list));
  21.     }
  22.  
  23.     private static int missingInt(ArrayList <Integer> list) {
  24.         for (int i = 1; i <= list.size(); i++)
  25.             if (!list.contains(i))
  26.                 return i;
  27.         return 0;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement