摘要: 1 """ 2 You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their node 阅读全文
posted @ 2020-02-17 22:49 yawenw 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 1 """ 2 Reverse a singly linked list. 3 Example: 4 Input: 1->2->3->4->5->NULL 5 Output: 5->4->3->2->1->NULL 6 """ 7 8 """ 9 两种解法 10 解法一:迭代法 11 是先申请一个p 阅读全文
posted @ 2020-02-17 22:47 yawenw 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 1 """ 2 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. 3 To represent a cycle in the given linked lis 阅读全文
posted @ 2020-02-17 22:45 yawenw 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 1 """ 2 链表插入排序 3 """ 4 """ 5 难点在于设计链表,插入排序时如何找到插入位置,并恢复好下一个遍历结点的位置 6 所以需要两个while循环,第一个是整体遍历,第二个是找插入位置 7 """ 8 class ListNode: 9 def __init__(self, x): 阅读全文
posted @ 2020-02-17 22:43 yawenw 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 1 """ 2 Sort a linked list in O(n log n) time using constant space complexity. 3 Example 1: 4 Input: 4->2->1->3 5 Output: 1->2->3->4 6 Example 2: 7 In 阅读全文
posted @ 2020-02-17 22:42 yawenw 阅读(139) 评论(0) 推荐(0) 编辑