83. 删除排序链表中的重复元素
题目链接
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/submissions/
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
题目描述
题目分析
注意是值的比较
注意head为空的情况
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
if(head == nullptr) return head;
ListNode* cur = head;
while(cur->next != nullptr){
if(cur->val == cur->next->val){//
cur->next = cur->next->next;
}else{
cur = cur->next;
}
}
return head;
}
};