标签:
基础题
注意要bug free看清楚细节得
public class Solution { public ListNode removeElements(ListNode head, int val) { if(head==null ) return null; ListNode h = new ListNode(-1); h.next = head; ListNode n = head, pre = h; while(n!=null){ if(n.val==val){ pre.next = n.next; }else{ pre = pre.next; } n =pre.next; } return h.next; } }
标签:
原文地址:http://www.cnblogs.com/jiajiaxingxing/p/4452264.html