/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode deleteNode(ListNode head, int val) { if (head == null) return head; if (head.val == val) return head.next; head.next = deleteNode(head.next, val); return head; } }