import java.util.*; /* * public class ListNode { * int val; * ListNode next = null; * public ListNode(int val) { * this.val = val; * } * } */ public class Solution { public ListNode deleteNode (ListNode head, int val) { while(head.val == val){ head = head.next; } ListNode pre = head; while(pre != null && pre.next!=null){ if(pre.next.val == val){ pre.next = pre.next.next; }else{ pre = pre.next; } } return head; } }