相同数字异或为0
不同为1
class Solution {
public:
int singleNumber(vector<int>& nums) {
int ret = 0;
for (int e: nums) ret ^= e;
return ret;
}
};
160. 相交链表
class Solution {
public:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
if(headA==NULL||headB==NULL) return NULL;
ListNode*pa = headA;
ListNode*pb = headB;
while(pa!=pb){
pa = pa==NULL?headB:pa->next;
pb = pb==NULL?headA:pb->next;
}
return pa;
}
};