Skip to content

Commit 680df79

Browse files
Time: 914 ms (66.90%) | Memory: 56.4 MB (67.77%) - LeetSync
1 parent 75182de commit 680df79

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, val=0, next=None):
4+
# self.val = val
5+
# self.next = next
6+
class Solution:
7+
def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:
8+
curr = head
9+
while curr and curr.next:
10+
curr = curr.next
11+
while curr and curr.next and curr.next.val != 0:
12+
curr.val += curr.next.val
13+
curr.next = curr.next.next
14+
curr = curr.next
15+
16+
head = head.next
17+
curr = head
18+
while curr and curr.next and curr.next.next:
19+
curr.next = curr.next.next
20+
curr = curr.next
21+
curr.next = None
22+
return head

0 commit comments

Comments
 (0)