题解 | #反转链表#

反转链表

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

  1. the Linklist is empty head == None
  2. the linklist has only one node head.next == None

and the condition of while as well

全部评论

相关推荐

ldyllic:飞神,985+美团+腾讯+京东,无敌飞飞神
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务