Untitled

mail@pastecode.io avatar
unknown
java
15 days ago
912 B
3
Indexable
Never
import java.util.*;
public class Solution
{
  public static int findMissingNumber(int[] a ){

    HashSet<Integer> set = new HashSet<Integer>();

    for(int i=0;i<a.length;i++){
      set.add(a[i]);
    }

    for(int i=1;i<=a.length;i++)
    {
      if(!set.contains(i))
      return i;
    }

return -1;

  }

  public static int findDuplicateNumber(int[] a)
  {

    HashSet<Integer> set = new HashSet<Integer>();

    for(int i=0;i<a.length;i++){
      if(!set.add(a[i]))
      return a[i];
    }

    return -1;

  }


    public static Vector<Integer> findNumbers(int[] a)
    {
      //You can code here

      Vector<Integer> result = new Vector<Integer>();

      int missingNum=findMissingNumber(a);
      int duplicateNum=findDuplicateNumber(a);

      result.add(missingNum);
      result.add(duplicateNum);

      return result;


      
    }
}
Leave a Comment