You are given a linked list of numbers. Sort the list in ascending order using the insertion sort method and return the sorted list.
How insertion sort works:
• Start with the first number as a sorted list.
• Take the next number from the list and place it in the correct position in
the sorted part.
• Repeat until all numbers are sorted.
Input: head = [3,1,4,2]
Output: [1,2,3,4]
Explanation:
Step by step, the list is sorted from [3] → [1,3] → [1,3,4] → [1,2,3,4].
Input: head = [7,2,5,3,1]
Output: [1,2,3,5,7]
Accepted:
Submission: