18.2 Write a method to shuffle a deck of cards. It must be a perfect shuffle—in other words, each of the 52! permutations of the deck has to be equally likely. Assume that you are given a random number generator which is perfect. 这道题让我们实现一个洗牌的算法,实际上洗…
Given two arrays A and B of equal size, the advantage of A with respect to B is the number of indices i for which A[i] > B[i]. Return any permutation of A that maximizes its advantage with respect to B. Example 1: Input: A = [2,7,11,15], B = [1,10,4,…
function shuffle(arr){ var len = arr.length; for(var i = 0;i<len -1;i++) { var idx = Math.floor(Math.random() * (len - 1)); console.log("idx",idx); var temp = arr[idx]; console.log("temp",temp); arr[idx] = arr[len - i - 1]; console.…