Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.List;
- import java.util.ArrayList;
- public class MissingInt {
- public static void main(String args[]){
- ArrayList<Integer> list = new ArrayList <> ();
- list.add(1);
- // list.add(2);
- // list.add(3);
- // list.add(4);
- // list.add(6);
- // list.add(7);
- // 1 2 3 4 6 7
- // 1 1 1 1 1 1
- // 1
- System.out.println(missingInt(list));
- }
- private static int missingInt(ArrayList <Integer> list) {
- for (int i = 1; i <= list.size(); i++)
- if (!list.contains(i))
- return i;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement