<reponame>Next-Gen-UI/Code-Dynamics<filename>Leetcode/2001-3000/2046. Sort Linked List Already Sorted Using Absolute Values/2046.py<gh_stars>0
class Solution:
  def sortLinkedList(self, head: Optional[ListNode]) -> Optional[ListNode]:
    prev = head
    curr = head.next

    while curr:
      if curr.val < 0:
        prev.next = curr.next
        curr.next = head
        head = curr
        curr = prev.next
      else:
        prev = curr
        curr = curr.next

    return head

Sort Linked List Already Sorted Using Absolute Values/2046.py<gh_stars>0
class Solution:
  def sortLinkedList(self, head: Optional[ListNode]) -> Optional[ListNode]:
    prev = head
    curr = head.next

    while curr:
      if curr.val < 0:
        prev.next = curr.next
        curr.next = head
        head = curr
        curr = prev.next
      else:
        prev = curr
        curr = curr.next

    return head