class Solution { public: int singleNumber(int A[], int n) { sort(A, A+n); int last = A[0]; int time = 1; for (int i=1; i<n; i++) { if (last != A[i]) { if(time == 3) { time = 1; last = A[i]; continue; } return last; } time++; } if (time != 3) return last; } };
一时想不出线性的方法
LeetCode Single Number II,布布扣,bubuko.com
原文:http://www.cnblogs.com/lailailai/p/3681737.html