Remove Linked List Elements

/**
 * 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;
    }
}
原文地址:https://www.cnblogs.com/wangcl-8645/p/11240059.html