题解 | #反转链表#
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
原本第一次用的是递归,但是报错maximum recursion depth 通过 import sys print(sys.getrecursionlimit()) 之后显示的是1000 但是只能运行1-998 所以就不懂了
第二个方法通俗易懂 直接遍历链表 cur,随着遍历 cur.next = None newhead= cur
需要注意地方是 这样操作时 需要提前再来一个post= cur.next
and of coures that for the algorithm of LinkList, we should always pay attenetion two case special
- the Linklist is empty head == None
- the linklist has only one node head.next == None
and the condition of while as well