【leetcode】83-Remove Duplicates from Sorted List

problem

Remove Duplicates from Sorted List

The basic usage of linked list is investigated.

code

/**

* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x): val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode
* deleteDuplicates(ListNode* head) {
ListNode
* cur = head;
while(cur && cur->next)//null is error.
{
if(cur->val == cur->next->val) cur->next = cur->next- >next;
else cur = cur->next; //
}
return head;
}
};

Reference

1. Remove Duplicates from Sorted List ;

End

/**

* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x): val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode
* deleteDuplicates(ListNode* head) {
ListNode
* cur = head;
while(cur && cur->next)//null is error.
{
if(cur->val == cur->next->val) cur->next = cur->next- >next;
else cur = cur->next; //
}
return head;
}
};

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3987 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.