LeetCodeのSingle Number
554 ワード
Key:同じ2つの整数が0であるか、0と0でない整数がこの数であるかは、配列に1つの数しか現れないため、すべての証明書が1つまたは複数で答えを得ることができ、c++の異またはフラグは^
class Solution {
public:
int singleNumber(int A[], int n) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
if (n<1){
return 0;
}
int key = A[0] ;
for (int i = 1; i < n ; i++){
key = key^A[i];
}
return key;
}
};