//反转链表 -- 迭代
/*
只需要完成逆置链表函数
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};
*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode *prev = nullptr;
ListNode *cur = pHead;
while (cur)
{
ListNode *next = cur->next;
cur->next = prev;
prev = cur, cur = next;
}
return prev;
}
};
/*
只需要完成逆置链表函数
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};
*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode *prev = nullptr;
ListNode *cur = pHead;
while (cur)
{
ListNode *next = cur->next;
cur->next = prev;
prev = cur, cur = next;
}
return prev;
}
};
2020-05-06
在牛客打卡14天,今天学习:刷题 3 道/代码提交 3 次
全部评论
相关推荐
01-07 20:03
蚌埠坦克学院 Java
李橙子:结果虽不够理想,但过程本身已是宝贵的淬炼。能把学习机会放在薪酬之前,证明你目光长远。先踏实进去,用这段时间扎实学好Python后端,把公司项目吃透,你的价值会在下一份工作中完全体现。这个起点,值得。 点赞 评论 收藏
分享
点赞 评论 收藏
分享

华为HUAWEI公司氛围 740人发布