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

前端 未结 12 936
梦谈多话
梦谈多话 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:26

    Java implementation: (Based on @Ben Voigt)

    BigInteger fact=1;
    int sum=0;
    int prod=1;
    int x,y; // The 2 missing numbers
    int n=a.length;
    int max=MIN_VALUE;
    
    for (int i=0; i

提交回复
热议问题