Tap here to switch tabs
Problem
Submissions

Problem: Merge Nodes in Between Zeros

med
30 min
Try to solve the Merge Nodes in Between Zeros problem.

Statement

You are given the head of a linked list containing a sequence of integers separated by nodes with a value of 00. The linked list begins and ends with nodes having Node.val equal to 00.

For every pair of consecutive 00 nodes, merge all intermediate nodes into a single node whose value is the sum of all the merged nodes. The resulting linked list must not contain any nodes with a value of 00.

Return the head of the modified linked list.

Constraints:

  • The number of nodes in the list is in the range [3,2imes105][3, 2 imes 10^5].

  • 0≤0 \leq Node.val ≤1000\leq 1000

  • There are no two consecutive nodes with Node.val =0= 0.

  • The beginning and end of the linked list have Node.val =0= 0.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Merge Nodes in Between Zeros

med
30 min
Try to solve the Merge Nodes in Between Zeros problem.

Statement

You are given the head of a linked list containing a sequence of integers separated by nodes with a value of 00. The linked list begins and ends with nodes having Node.val equal to 00.

For every pair of consecutive 00 nodes, merge all intermediate nodes into a single node whose value is the sum of all the merged nodes. The resulting linked list must not contain any nodes with a value of 00.

Return the head of the modified linked list.

Constraints:

  • The number of nodes in the list is in the range [3,2imes105][3, 2 imes 10^5].

  • 0≤0 \leq Node.val ≤1000\leq 1000

  • There are no two consecutive nodes with Node.val =0= 0.

  • The beginning and end of the linked list have Node.val =0= 0.