Find 2 missing numbers in an array of integers with two missing values

前端 未结 12 912
梦谈多话
梦谈多话 2021-01-30 09:33

How do you do this? The values are unsorted but are of [1..n] Example array [3,1,2,5,7,8]. Answer: 4, 6

I saw this solution in

12条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 10:35

    works for any number of missing elements: you can format the code a little .. but it works on duplicate and non duplicate entries also:

    public static void main(String args[] ) throws Exception {
    
            Scanner input = new Scanner(System.in);
            System.out.println("Enter no. of students in the class");
            int N = input.nextInt();
            List l = new ArrayList();
            int Nn=N;
            System.out.println("Enter the roll numbers");
            for(int i=0;i

提交回复
热议问题