PYTHON SOL WITH LINE BY LINE EXPLANATION
I have already added the required comments and explanation and if you still have any doubts comment down\n\n        \n        \n        """\n        We will cre
I have already added the required comments and explanation and if you still have any doubts comment down\n\n        \n        \n        """\n        We will create a sorted linked list based on the given linkedlist by taking one val at a time and\n        iterating and checking with prev and next pointer \n        \n        """\n        \n        \n        #The basic idea is we will create a dummy variable\n        #the reason we are creating a dummy variable so that we an have a pointer\n        #to our prev_pointer and curr_pointer \n        #and the reason we are taking prev pointer and next pointer so that we can compare it with \n        #the curr.val and place it accordingly\n        \n        \n        """\n        Initially the prev pointer will be pointing to our dummy var and the next pointer will be pointing to the prev.next \n        \n        And each iteration we will be moving both our pointers\n        \n        \n        """\n        dummy_head = ListNode()\n        \n        curr = head\n        \n        while curr:\n            prev_pointer = dummy_head\n            next_pointer = prev_pointer.next\n            \n            \n            #Now we will try to find out what would be the correct position be for the curr\n            #value we are at\n            \n            while next_pointer:  #Dont include prev_pointer coz initially it will be null\n                \n                if curr.val < next_pointer.val:\n                    break \n                    \n                \n                prev_pointer = prev_pointer.next\n                next_pointer = next_pointer.next\n                \n            #Now that we find out the correct poistion all we need to do is update our pointers\n            \n            #point to be noted if we simply do curr = curr.next then we will loose the track of original/previous curr.next \n            \n            #As we are initializing the curr.next = next_pointer\n            \n            #So to avoid that we are storing it in a temp variable \n             \n            temp = curr.next\n            \n            curr.next = next_pointer\n            prev_pointer.next = curr\n            \n            curr = temp\n            \n        return dummy_head.next # Coz the dummy_head has no value that is 0 so we will start from the next node\n\t\t\n\t\t\n**UPVOTE IF YOU FIND IT HELPFUL**\n
['Linked List', 'Two Pointers', 'Python', 'Python3']