剑指offer15: 反转链表
头插法
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode* h = NULL;
for(ListNode* p = pHead; p; ){
ListNode* tmp = p -> next;
p -> next = h;
h = p;
p = tmp;
}
return h;
}
};
头插法
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode* h = NULL;
for(ListNode* p = pHead; p; ){
ListNode* tmp = p -> next;
p -> next = h;
h = p;
p = tmp;
}
return h;
}
};
2020-05-12
在牛客打卡33天,今天学习:刷题 5 道/代码提交 5 次
全部评论
相关推荐