---
# System prepended metadata

title: 2095. Delete the Middle Node of a Linked List
tags: [Leetcode, Linked List, Medium]

---

# 2095. Delete the Middle Node of a Linked List
###### tags: `Leetcode` `Medium` `Linked List`
Link: https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/description/
## 思路
找middle node一定是用快慢指针
遇到奇数个node 如果想要靠前的node当middle node 那么while回圈的条件就是```fast!=null && fast.next!=null```; 否则就是```fast.next!=null && fast.next.next!=null```
找到middle node并且记录一下它前面的node即可得到答案
## Code
```java=
class Solution {
    public ListNode deleteMiddle(ListNode head) {
        ListNode dummyNode = new ListNode(0, head);
        ListNode prev = dummyNode;
        ListNode slow = head, fast = head;
        while(fast!=null && fast.next!=null){
            prev = slow;
            slow = slow.next;
            fast = fast.next.next;
        }
        ListNode next = slow.next;
        prev.next = next;
        return dummyNode.next;
    }
}
```