python 鏈表逆轉

class LinNode:
    def __init__(self, val):
        self.val = val
        self.next = None


def LinReverse(l):
    h1 = l
    h2 = l.next
    h1.next = None
    h3 = None
    while h2:
        h3 = h2.next
        h2.next = h1
        h1 = h2
        h2 = h3
    return h1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章