Home > Back-end >  An algorithm implementation
An algorithm implementation

Time:02-25

Problem: two contains six arrays of integers, compare several same integer

The pursuit of the highest performance, spent several hours yesterday to do improvement, found it very simple, you to try it on

CodePudding user response:

It is good to poor with collection occurring simultaneously

For example
 public class Sample {
Public static void main (String [] args) {
Int [] num1={1, 2, 3, 8, 9, 5};
Int [] num2={2, 3, 4, 5, 6, 7};

List L1=new ArrayList<> (a);
List L2=new ArrayList<> (a);
For (int n: num1)
L1. Add (n);
For (int n: num2)
L2. Add (n);

L1. RetainAll (l2);//the intersection of two sets of
System. The out. Println (l1);

}
}

CodePudding user response:

Add two arrays have, in accordance with the smallest to complete
  • Related