简单题
1 class Solution { 2 public: 3 int singleNumber(int A[], int n) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 int ans = 0; 7 for (int i = 0; i < n; i++) ans ^= A[i]; 8 return ans; 9 } 10 };
C#
1 public class Solution { 2 public int SingleNumber(int[] nums) { 3 int ans = 0; 4 for (int i = 0; i < nums.Length; i++) ans ^= nums[i]; 5 return ans; 6 } 7 }