示例#1
0
            r = r.next
        elif l.val < r.val:
            s.append(l)
            l = l.next
        elif l.val > r.val:
            s.append(r)
            r = r.next
    # Append the rest of l
    while l != None:
        s.append(l)
        l = l.next
    # Append the rest of r
    while r != None:
        s.append(r)
        r = r.next

    for i in range(1, len(s)):
        first = s[i - 1]
        second = s[i]
        first.next = second

    return s[0]


from LINK import makeLL, printLL
a = [1, 3, 5, 7, 9]
b = [2, 4, 6, 8, 10]
headA = makeLL(a)
headB = makeLL(b)

printLL(A(headA, headB))
示例#2
0
            d[curr] = True
        curr = curr.next
    return False


# LC SOLN
# Using slow and fast pointers to check for cycle
# n time but O(1) space
def B(head):
    if not head or not head.next:
        return False
    slow = head
    fast = head.next
    while slow != fast:
        if not fast or not fast.next:
            return False
        slow = slow.next
        fast = fast.next.next
    return True


from LINK import makeLL, printLL, getTail
a = [3, 2, 0, -4]
head = makeLL(a)
tail = getTail(head)

# Make cycle between -4 -> 2
tail.next = head.next

print B(head)
示例#3
0
	if not ret:
		return
	ret[0] = node(ret[0])
	# kntime
	for i in range(1,len(ret)):
		ret[i] = node(ret[i])
		ret[i-1].next = ret[i]
	return ret[0]

import heapq as hq
def B(lists):
	h = []
	for i in lists:
		head = i 
		while head:
			h.append(head.val)
			head = head.next
	hq.heapify(h)
	return h


from LINK import makeLL, printLL
a=[1,4,5]
b=[1,3,4]
c=[2,6]
headA=makeLL(a)
headB=makeLL(b)
headC=makeLL(c)

printLL(A([headA,headB,headC]))