Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
870 B
3
Indexable
Never
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def deleteNodes(self, head: ListNode, m: int, n: int) -> ListNode:
        
        pointer1 = dup = ListNode()
        pointer2 = head
        temp = m
        while pointer2 and pointer2.next: 
            pointer1.next = pointer2
            pointer1 = pointer1.next
            print(pointer1.val)
            pointer2 = pointer2.next
            m-=1
            c=0
            if m == 0: 
                for i in range(n): 
                    if pointer2.next :
                        c+=1
                        pointer2= pointer2.next
                if c!=n:
                    pointer1.next = None
                m = temp
        return dup.next