删除链表结点的两种解法1234567891011121314151617/** * 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 null; if(head.val == val) return head.next; else head.next = deleteNode(head.next,val); return head; }}123456789101112131415161718class Solution { public ListNode deleteNode(ListNode head, int val) { ListNode pre = head; ListNode cur = head.next; if (head.val == val) return head.next; while (cur != null) { if (cur.val == val) { pre.next = cur.next; } pre = cur; cur = cur.next; } return head; }}