Created
May 18, 2022 04:45
-
-
Save thekhairul/b8a90da77a02c5760ee8b7b506d8600b to your computer and use it in GitHub Desktop.
Leetcode 876: Middle of a linked list - python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def middleNode(head): | |
#find total length | |
count = 1 | |
cur = head | |
while cur.next: | |
count += 1 | |
cur = cur.next | |
#find mid | |
mid = int(count/2 + 1) | |
#find mid node | |
cur = head | |
count = 1 | |
while count <= mid: | |
if count == mid: | |
return cur | |
cur = cur.next | |
count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment