Some Efficient Algorithms

1. For Integer,you can consider the following:

  *2   <<1 

  /2  ≡ >>1

  %2  ≡  &1

2. Generate a non-repeating numbers random array ranging from 1-50

     int[] result = new int[50];

        ArrayList<Integer> numPool = new ArrayList<Integer>();

        for (int i = 0; i < 50; i++) {

            numPool.add(i);

        }

        Random random = new Random();

        for(int j=0;j<50;j++){

            int index = random.nextInt(numPool.size());

            result[j]=numPool.get(index);

            numPool.remove(index);

        } 

or you can random sort the numPool

你可能感兴趣的:(algorithms)