可能重复:
检查数组 B 是否是 A 的排列
给定 2 个大小相等的a未排序整数数组。b确定是否b是 的排列a。这可以在O(n) timeand中完成O(1) space吗?
我想到的第一个解决方案是使用XOR, 即XOR all the elements of a and b and if the resultant is 0 which means that b is a permutation of a. 但他给出了这种方法失败的例子。例如 -
a: [1 6 0 0 4] -- b: [1 0 6 1 5]
a: [1 6 0 0 5] -- b: [1 0 6 1 4]
任何人有任何想法,如何做到这O(n) time一点O(1) space?