目的:
删除链表的中间节点
代码实现:
public class Node{ public int value; public Node next; public Node(int data){ this.value=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; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。