コード例 #1
0
ファイル: exam.py プロジェクト: flydsc/algorithmsinpython

def find(headA, headB):
    if not headA or not headB:
        return None
    nodeA = headA
    while nodeA.next:
        nodeA = nodeA.next
        print nodeA
    nodeA.next = headA
    slow = fast = headB
    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next
        if slow == fast:
            break
    if not fast or not fast.next:               
        nodeA.next = None
        return None
    slow = headB
    while slow != fast:
        slow = slow.next
        fast = fast.next
    nodeA.next = None
    return slow

node = find(list1.get_head(), list2.get_head())
print node
print list1
print list2