import java.util.*;


public class Solution {
    public ListNode deleteNode (ListNode head, int val) {
        if(head.val==val) return head.next;
        if (head.next==null) return head;
        deleteNode(head.next,val);
        if (head!=null&&head.next.val==val) head.next = head.next.next;
        return head;
    }
}

递归