xxxxxxxxxx
function getArrayMutations(arr, perms = [], len = arr.length) {
if (len === 1) perms.push(arr.slice(0))
for (let i = 0; i < len; i++) {
getArrayMutations(arr, perms, len - 1)
len % 2 // parity dependent adjacent elements swap
? [arr[0], arr[len - 1]] = [arr[len - 1], arr[0]]
: [arr[i], arr[len - 1]] = [arr[len - 1], arr[i]]
}
return perms
}
xxxxxxxxxx
var empty struct{} // variable with empty value
nums := []int{1,2,2,3,3,3,4}
hmap := make(map[int]struct{})
for i:=0; i<len(nums); i++ {
hmap[nums[i]] = empty
}