标签:des c style class blog code
class Solution { public: ListNode *swapPairs(ListNode *head) { ListNode *a = NULL; ListNode *b = NULL; ListNode *tail = NULL; ListNode *nhead = NULL; a = head; while (a != NULL && (b = a->next) != NULL) { a->next = b->next; b->next = a; if (tail != NULL) { tail->next = b; } else { nhead = b; } tail = a; a = a->next; } if (nhead == NULL) { nhead = head; } return nhead; } };
准备六级,水一发
LeetCode Swap Nodes in Pairs,布布扣,bubuko.com
标签:des c style class blog code
原文地址:http://www.cnblogs.com/lailailai/p/3766541.html