Distinguishing extra element from two arrays?

后端 未结 19 643
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-28 09:45

One of my friend was asked this question in an interview -

  • You have given two integer arrays each of size 10.
  • Both contains 9 equal elements (say 1 t
19条回答
  •  情话喂你
    2020-12-28 10:35

    Given two arrays say A1 of size 'n' and A2 of size 'n-1', both the arrays have same element except one which we have to find.

    Note: elements in A1 can be repeated.

    Example:

    A1:{2,5,5,3}

    A2:{2,5,3}

    Output: 5

    A1:{1,2,3,3,3}

    A2:{2,3,1,3}

    Output: 3

    public static void main(String args[])
    {
        int[] a ={1,2,3,3,3};
        int[] b ={2,3,1,3};
        int flag=1;
        int num=0;
        List lst = new ArrayList<>(b.length);
        for(int i : b)
            lst.add(Integer.valueOf(i));
    
    
        for(int i=0;i

提交回复
热议问题