标签:list mic pen alt tco inf 面试题 delete new
javaO(N)
/** * 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) { ListNode firstNode = new ListNode(-1); firstNode.next = head; ListNode curr = firstNode; while(curr!=null && curr.next != null){ if(curr.next.val == val){ curr.next = curr.next.next; } curr = curr.next; } return firstNode.next; } }
标签:list mic pen alt tco inf 面试题 delete new
原文地址:https://www.cnblogs.com/oldby/p/12683014.html