合并零之间的节点
力扣链接
代码
class Solution {
public ListNode mergeNodes(ListNode head) {
ListNode newHead = new ListNode();
ListNode t = head.next;
ListNode t2 = newHead;
int sum = 0;
while (t != null) {
sum += t.val;
if (t.val == 0) {
t2.val = sum;
if (t.next != null) {
t2.next = new ListNode();
t2 = t2.next;
}
sum = 0;
}
t = t.next;
}
return newHead;
}
}