/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* deleteNode(ListNode* head, int val) {
if(head->val==val) return head->next;
ListNode* p=head->next;
ListNode* pre=head;
while(p){
if(p->val==val) {
pre->next=p->next;
p=p->next;
}
else {
pre=p;
p=p->next;
}
}
return head;
}
};