Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions practice/leetcode/solutions_01500/solution_01669.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,22 @@ def mergeInBetween(self, list1, a, b, list2):
:type list2: ListNode
:rtype: ListNode
"""
p1 = p2 = list1
p3 = list2
start = stop = None
i = 0
while p1:
if p1 and p1.next and (i+1) == a:
start = p1
if p1 and i == b:
stop = p1.next
i += 1
p1 = p1.next

start.next = list2

while p3:
if p3 and p3.next is None:
p3.next = stop
break
p3 = p3.next

return p2
prev_a = list1
for _ in range(a - 1):
prev_a = prev_a.next

after_b = prev_a
for _ in range(b - a + 2):
after_b = after_b.next

tail2 = list2
while tail2.next:
tail2 = tail2.next

prev_a.next = list2
tail2.next = after_b

return list1


class TestSolution(unittest.TestCase):
Expand Down
Loading