链表-删除链表的中间节点

//删除链表的中间节点
public class Node{
    public int value;
    public Node next;
    public Node(int data){
        this.data=data;
    }
}
public Node removeMidNode(Node head){
    if(head==null||head.next==null){
        return head;
    }
    if(head.next.next==null){
        return head.next;
    }
    Node pre=head;
    Node cur=head.next.next;
    while(cur.next!=null&&cur.next.next!=null){
        pre.pre.next;
        cur=cur.next.next;
    }
    pre.next=pre.next.next;
    return head;
}

猜你喜欢

转载自blog.csdn.net/weixin_42146769/article/details/88386902