Patreon: https://www.patreon.com/user?u=35312452
Connect with me on Linkedin: / helmy47
Python Code:
-------------------------------------------------------------
class Solution:
def oddEvenList(self, head):
even_head= ListNode(None)
even= even_head
odd_head= ListNode(None)
odd= odd_head
while head:
odd.next= head
odd= odd.next
even.next= head.next
even= even.next
head= head.next.next if even else None
odd.next= even_head.next
return odd_head.next
--------------------------------------------------------------------
Time complexity: O(N), it has to iterate through the length of the dataset N.
Space complexity: O(1), regardless of the dataset size, the space complexity is constant.
Watch video LeetCode 328: Odd Even Linked List Solution Explained - Python online without registration, duration hours minute second in high quality. This video was added by user HelmyCodeCamp 27 May 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 104 once and liked it 4 people.