Ejemplo n.º 1
0
                head = smaller
                C = smaller
            else:
                C.next = smaller
                C = C.next
        

        nonEmpty = None
        if A is not None:
            nonEmpty = A
        elif B is not None:
            nonEmpty = B

        while nonEmpty is not None:
            if C is None:
                C = nonEmpty
                head = nonEmpty
            else:
                C.next = nonEmpty
                C = C.next
            nonEmpty = nonEmpty.next
        
        return head

A = LinkedList.getSortedLinkedList(10)
LinkedList.printLinkedList(A)
B = LinkedList.getSortedLinkedList(1)
LinkedList.printLinkedList(B)
sol = Solution()
C = sol.mergeTwoLists(A,B)
LinkedList.printLinkedList(C)
import LinkedList

class Solution:
    # @param A : head node of linked list
    # @return the head node in the linked list
    def deleteDuplicates(self, A):
        head = A
        prev = head
        next = A.next
        while next is not None:
            while next is not None and next.val == prev.val:
                next = next.next
            prev.next = next
            prev = prev.next
            if next is not None:
                next = next.next
        return head

A = LinkedList.getSortedLinkedList(2)
LinkedList.printLinkedList(A)
sol = Solution()
A = sol.deleteDuplicates(A)
LinkedList.printLinkedList(A)