您当前的位置: 首页 >  leetcode

LeetCode Algorithm 83. 删除排序链表中的重复元素

发布时间:2021-12-07 17:48:13 ,浏览量:0

83. 删除排序链表中的重复元素

Ideas

这题挺简单的,直接一次遍历,如果当前遍历的元素val跟下一个元素的val相等,说明是重复元素,直接把当前item的next指向item->next->next。

Code C++
class Solution { public: ListNode* deleteDuplicates(ListNode* head) { if (!head) { return head; } ListNode* item = head; while (item->next) { if (item->val == item->next->val) { item->next = item->next->next; } else { item = item->next; } } return head; } }; 
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108697博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.5242s