题解 | #寻找奇数#
寻找奇数
https://www.nowcoder.com/practice/849b9e545f4742398d278f5dc4e003d2
#include <stdio.h> int main() { // a ^ a = 0; // a ^ 0 = a; int n = 0; scanf("%d", &n); int num = 0; int sum = 0; for (int i = 1; i <= n; i++) { scanf("%d", &num); sum = sum ^ num;//出现偶数次的数异或后一定为0,最后剩下的数一定是出现奇数次的数 } printf("%d\n", sum); return 0; }