<p>Given the <code>head</code> of a linked list, we repeatedly delete consecutive sequences of nodes that sum to <code>0</code> until there are no such sequences.</p>

<p>After doing so, return the head of the final linked list.&nbsp; You may return any such answer.</p>

<p>&nbsp;</p>
<p>(Note that in the examples below, all sequences are serializations of <code>ListNode</code> objects.)</p>

<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> head = [1,2,-3,3,1]
<strong>Output:</strong> [3,1]
<strong>Note:</strong> The answer [1,2,1] would also be accepted.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> head = [1,2,3,-3,4]
<strong>Output:</strong> [1,2,4]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> head = [1,2,3,-3,-2]
<strong>Output:</strong> [1]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The given linked list will contain between <code>1</code> and <code>1000</code> nodes.</li>
	<li>Each node in the linked list has <code>-1000 &lt;= node.val &lt;= 1000</code>.</li>
</ul>


# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next

class Solution:
    GUARD_VAL = math.inf
    def removeZeroSumSublists(self, head: Optional[ListNode]) -> Optional[ListNode]:
        # Adding dummy start and dummy end with math.inf values.
        dummy_start: ListNode = ListNode(self.GUARD_VAL, head)
        head = dummy_start
        while head.next is not None:
            head = head.next
        head.next = ListNode(self.GUARD_VAL, None)

        from_node: ListNode = dummy_start
        
        while from_node.val != self.GUARD_VAL or from_node == dummy_start:
            while self._removed_zero_sublist(from_node):
                ...
            from_node = from_node.next

        # Remove dummy end.
        head = dummy_start
        while head.next.val != self.GUARD_VAL:
            head = head.next
        
        head.next = None
        return dummy_start.next

    def _removed_zero_sublist(self, from_node: ListNode) -> bool:
        to_node: ListNode = from_node.next
        nodes_within: int = 0
        sum_within: int = 0

        while to_node.val != self.GUARD_VAL and (sum_within != 0 or nodes_within == 0):
            sum_within += to_node.val
            nodes_within += 1
            to_node = to_node.next
        
        if sum_within == 0 and nodes_within > 0:
            from_node.next = to_node
            return True
        return False

105