数组异或的交换,不能有下标相同的互换!!
public void swap(int[] arr, int a, int b) {
arr[a] = arr[a] ^ arr[b];
arr[b] = arr[a] ^ arr[b];
arr[a] = arr[a] ^ arr[b];
}
这里的a,b如果相同,最后会出现arr[a]=0,所以这里要排除a=b的情况
06-03
1367
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-19
3万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-02
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交