Delete the Middle Node of a Linked List LeetCode solution in Java

1
class Solution {
2
public ListNode deleteMiddle(ListNode head) {
3
// Base Condition
4
if (head == null || head.next == null) return null;
5
// Pointers Created
6
ListNode fast = head;
7
ListNode slow = head;
8
ListNode prev = head;
9

10
while (fast != null && fast.next != null) {
11
prev = slow;
12
slow = slow.next;
13
fast = fast.next.next;
14
}
15
prev.next = slow.next;
16
return head;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0