def number_to_linked_list(n): head = None for i in str(n): tmp = Node(int(i)) tmp.next = head head = tmp return head
def reverse_list(head): new_head = None cur = head while cur: node = Node(cur.data) node.next = new_head new_head = node cur = cur.next return new_head
def test_a1(self): head = Node(1) head.next = Node(1) head.next.next = Node(2) head.next.next.next = Node(2) head.next.next.next.next = Node(2) head.next.next.next.next.next = Node(3) result = remove_dupes_a(head) self.assertEqual(result.toList(), [1, 2, 3])
def test_b3(self): head = Node(1) head.next = Node(1) result = remove_dupes_b(head) self.assertEqual(result.toList(), [1])