题解 | #删除有序链表中重复的元素-I#
括号生成
http://www.nowcoder.com/practice/c9addb265cdf4cdd92c092c655d164ca
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
*
* @param head ListNode类
* @return ListNode类
*/
ListNode* deleteDuplicates(ListNode* head) {
// write code here
if(head==NULL||head->next==NULL)
return head;
ListNode*pre=head,*cur=head->next;
while(cur){
if(cur->val!=pre->val){
pre=cur;
cur=cur->next;
}
else{
pre->next=cur->next;
cur=pre->next;
}
}
return head;
}
};
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
*
* @param head ListNode类
* @return ListNode类
*/
ListNode* deleteDuplicates(ListNode* head) {
// write code here
if(head==NULL||head->next==NULL)
return head;
ListNode*pre=head,*cur=head->next;
while(cur){
if(cur->val!=pre->val){
pre=cur;
cur=cur->next;
}
else{
pre->next=cur->next;
cur=pre->next;
}
}
return head;
}
};