算法+数据结构
刷题(手机号登录)
https://leetcode.cn/problemset/all/
异或交换
public static void main(String[] args) { int a = 10; int b = 15; a = a ^ b; b = a ^ b; a = a ^ b; System.out.println(a + " " + b); }
一个数组中有一种数出现了奇数次,其他数都出现了偶数次,找到这个偶数次数
public static void main(String[] args) { int num = 0; int[] arrays = {1, 2, 3, 1, 2, 3, 3}; for (int i = 0; i < arrays.length; i++) { num = num ^ arrays[i]; } System.out.println(num); }