Py学习  »  Python

在python中,给定一个单独的linkedlist,将它分成两半(大约中间值)并将每一半倒转

swapd • 6 年前 • 260 次点击  

我可以倒过来,但对如何访问linkedlist的中值感到困惑

def reverseLinkedList(head):

    current =  head
    previous = None
    nextNode = None

    while current:
        nextNode = current.nextNode
        current.nextNode = previous

        previous = current
        current = nextNode

    return previous

有人能帮忙解决吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40230
文章 [ 1 ]  |  最新文章 6 年前