<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:
    def removeZeroSumSublists(self, head: Optional[ListNode]) -> Optional[ListNode]:
        temp = head
        ar = []
        while(temp != None):
            ar.append(temp.val)
            temp = temp.next
        # ar = ar[::-1]
        n = len(ar)
        sum = 0
        init = 10**4
        i = 0 
        while(i<n):
            sum = 0
            f = 0
            for j in range(i,n):
                sum += ar[j]
                if sum == 0:
                    print('sum == 0')
                    f = 1
                    break
            if f: 
                for x in range(i,j+1):
                    ar[x] = init
                i = max(i+1,j)
            else:
                i+=1
        # print(ar)
        h = None
        temp = None
        for i in range(n):
            if ar[i] != init:
                if h == None:
                    temp = ListNode(ar[i])
                    h = temp
                    temp.next = None
                else:
                    t = ListNode(ar[i])
                    temp.next = t
                    temp = t


        return h










        # if head.val == 5:
        #     h = ListNode(5)
        #     h.next = ListNode(3)
        #     h.next.next = None
        #     return h
        # return head

        # while(temp != None):
        #     sum += 0 
        #     temp = temp.next


        # while(temp != None):
        #     sum = 0
        #     cur = temp
        #     while(cur!= None):
        #         sum+= cur.val
        #         if sum == 0:
        #             temp = cur.next
        #         cur = cur.next
        




        
79