Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
class Solution { int FindSingleNumber(int num[], int n) { if(NULL == num || n <= 0) { return -1; } for(int i = 1; i < n; i++) { num[0] ^= num[i]; } return num[0] } }
这道题虽然很简单,在各种面试题中也经常可以见到,值得深入挖掘的是这种思考问题并运用已有知识解决问题的思路。