/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     public int val;
 *     public ListNode next;
 *     public ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public ListNode RemoveElements(ListNode head, int val) {
        if(head==null)
            return head;
        ListNode node=new ListNode(-1);
        ListNode temp=node;
        node.next=head;
        
        while(temp.next!=null){
           
            if(temp.next.val==val){
                temp.next=temp.next.next;
            }else{
                temp=temp.next;
            }
        }
        return node.next;
    }
}

 

 posted on 2019-07-24 18:30  JetaimeBeaucoup  阅读(70)  评论(0编辑  收藏  举报