|
| 1 | +<h2><a href="https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list/">1171. Remove Zero Sum Consecutive Nodes from Linked List</a></h2><h3>Medium</h3><hr><div><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> |
| 2 | + |
| 3 | +<p>After doing so, return the head of the final linked list. You may return any such answer.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p>(Note that in the examples below, all sequences are serializations of <code>ListNode</code> objects.)</p> |
| 7 | + |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre><strong>Input:</strong> head = [1,2,-3,3,1] |
| 11 | +<strong>Output:</strong> [3,1] |
| 12 | +<strong>Note:</strong> The answer [1,2,1] would also be accepted. |
| 13 | +</pre> |
| 14 | + |
| 15 | +<p><strong class="example">Example 2:</strong></p> |
| 16 | + |
| 17 | +<pre><strong>Input:</strong> head = [1,2,3,-3,4] |
| 18 | +<strong>Output:</strong> [1,2,4] |
| 19 | +</pre> |
| 20 | + |
| 21 | +<p><strong class="example">Example 3:</strong></p> |
| 22 | + |
| 23 | +<pre><strong>Input:</strong> head = [1,2,3,-3,-2] |
| 24 | +<strong>Output:</strong> [1] |
| 25 | +</pre> |
| 26 | + |
| 27 | +<p> </p> |
| 28 | +<p><strong>Constraints:</strong></p> |
| 29 | + |
| 30 | +<ul> |
| 31 | + <li>The given linked list will contain between <code>1</code> and <code>1000</code> nodes.</li> |
| 32 | + <li>Each node in the linked list has <code>-1000 <= node.val <= 1000</code>.</li> |
| 33 | +</ul> |
| 34 | +</div> |
0 commit comments