原题地址

 

经典题目。

所有数字异或,剩下的就是只出现一次的数字,因为其他出现两次的数字都没啦。T ^ T = 0

代码:

1 int singleNumber(int A[], int n) {
2   int res = 0;
3 
4   for (int i = 0; i < n; i++)
5     res = res ^ A[i];
6 
7   return res;
8 }

 

相关文章:

  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
猜你喜欢
  • 2021-10-25
  • 2021-07-25
  • 2021-06-10
  • 2021-06-11
  • 2021-06-27
  • 2022-01-20
  • 2021-06-19
  • 2021-11-25
相关资源
相似解决方案