2019-07-03 自我修养►数据结构与算法 找出链表的中点 python实现: 1234567891011121314151617181920212223242526272829303132333435363738394041424344class Node: def __init__(self, data, next): self.data = data self.next = nextdef find_mid_of_list(head): quick, slow = head, head i, j = 1, 2 while quick is not None: while j: quick = quick.next if quick is None: break j -= 1 if j == 2: return [slow] elif j == 1: return [slow, slow.next] while i: slow = slow.next if slow is None: break i -= 1 i, j = 1, 2 return Noneif __name__ == "__main__": import sys import os if len(sys.argv) < 2: print("useage:%s <num_list>" % sys.argv[0]) os._exit(-1) t = sys.argv[1] head = None for c in t: node = Node(c, None) node.next = head head = node for x in find_mid_of_list(head): print(x.data) Newer 19.Remove Nth Node From End of List Older 20.Valid Parentheses