Leetcode in Java && Oracle
421 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-04-12_13-03-59.png
40.4 KB
#medium
#N2181. Merge Nodes in Between Zeros
problem link
#solution
class Solution {
public ListNode mergeNodes(ListNode head) {
ListNode slow = head.next;
ListNode fast = head.next;
int sum=0;
while(fast!=null){
sum+=fast.val;
if(fast.val==0){
slow.val=sum;
slow.next=fast.next;
slow=slow.next;
sum=0;
}
fast=fast.next;
}
return head.next;
}
}