Skip to content

Commit 3cd8f1b

Browse files
authored
Merge pull request #1 from Vansh3000/Vansh3000-patch-1
Create DeleteTheMiddleNode(linkedlist).py
2 parents e881273 + 5792379 commit 3cd8f1b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

DeleteTheMiddleNode(linkedlist).py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'''
2+
Delete the middle node of linked list (2095)
3+
'''
4+
5+
class Solution:
6+
def deleteMiddle( self, head : Optional[ListNode]):
7+
if head == None or head.next == None:
8+
return None
9+
10+
slow = head
11+
fast = head.next.next
12+
13+
while fast and fast.next != None:
14+
slow = slow.next
15+
fast = fast.next.next
16+
17+
slow.next = slow.next.next
18+
return head

0 commit comments

Comments
 (0)