标签:color param head return node val link lis while
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { /** * @param head a ListNode * @param val an integer * @return a ListNode */ public ListNode removeElements(ListNode head, int val) { // Write your code here ListNode res = head; if(head==null) return null; while(head.next!=null){ if(head.next.val==val){ if(head.next.next!=null){ head.next = head.next.next; }else{ head.next=null; break; } }else{ head = head.next; } } if(head.val==val) return head.next; return res; } }
标签:color param head return node val link lis while
原文地址:http://www.cnblogs.com/haleny/p/6473132.html