码迷,mamicode.com
首页 > 其他好文 > 详细

Remove Linked List Elements

时间:2019-07-24 19:41:21      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:ext   else   val   lin   list   init   null   nod   lis   

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     public int val;
 *     public ListNode next;
 *     public ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public ListNode RemoveElements(ListNode head, int val) {
        if(head==null)
            return head;
        ListNode node=new ListNode(-1);
        ListNode temp=node;
        node.next=head;
        
        while(temp.next!=null){
           
            if(temp.next.val==val){
                temp.next=temp.next.next;
            }else{
                temp=temp.next;
            }
        }
        return node.next;
    }
}

 

Remove Linked List Elements

标签:ext   else   val   lin   list   init   null   nod   lis   

原文地址:https://www.cnblogs.com/wangcl-8645/p/11240059.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!