1
# Runtime: 50 ms (Top 81.38%) | Memory: 14.5 MB (Top 12.03%)2
# Definition for singly-linked list.4
# def __init__(self, val=0, next=None):9
self, head: Optional[ListNode], k: int10
) -> List[Optional[ListNode]]:16
# DON'T do following since this makes head become null21
# calculate the base size and the number of parts contain extra number22
size, extra = length // k, length % k24
# create empty list to store split parts25
res = [[] for _ in range(k)]27
# use two ptrs to split parts28
prev, cur = None, head32
# if this part contains extra number, it has (size+1) number33
for j in range(size + (1 if extra > 0 else 0)):34
prev, cur = cur, cur.next