代码改变世界

leetcode - Single Number

2013-10-14 10:37  张汉生  阅读(144)  评论(0编辑  收藏  举报

 

 1 class Solution {
 2 public:
 3     int singleNumber(int A[], int n) {
 4         // Note: The Solution object is instantiated only once and is reused by each test case.
 5         if (n<=0)
 6             return 0;
 7         int ans=0;
 8         for (int i=0; i<n; i++)
 9             ans ^= A[i];
10         return ans;
11     }
12 };