1# Runtime: 59 ms (Top 77.27%) | Memory: 14.3 MB (Top 57.10%)234# Definition for singly-linked list.5# class ListNode:6# def __init__(self, val=0, next=None):7# self.val = val8# self.next = next9class Solution:10def removeZeroSumSublists(self, head: Optional[ListNode]) -> Optional[ListNode]:11root = ListNode(0, head)12summ, d, node = 0, {}, root13while node:14summ += node.val15if summ in d:16prev = d[summ]17tmp = prev.next18tmp_sum = summ19while tmp != node:20tmp_sum += tmp.val21if tmp_sum in d and d[tmp_sum] == tmp:22d.pop(tmp_sum)23tmp = tmp.next24prev.next = node.next25node = prev26else:27d[summ] = node28node = node.next2930return root.next