![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
链表
liuwangleoooO
失败了 别给自己找理由 就是菜而已!
展开
-
python—判断链表是否有环并找到入环节点
文章目录判断链表是否有环并找到入环节点判断链表是否有环并找到入环节点class LNode: def __init__(self, val): self.val = val self.next = Nonedef exitLoop(head): if not head: return None p1 = p2 = head while p2 and p2.next: p1 = p1.next p2 = p2.next.next if p1原创 2021-04-26 12:31:22 · 236 阅读 · 0 评论 -
python—把链表的相邻元素翻转
class ListNode(): def __init__(self, val=0, next=None): self.val = val self.next = nextdef reverse(head): if head is None or head.next is None: return cur = head.next pre = head next = None # 当前节点的后继节点的后继节点原创 2021-02-25 07:11:28 · 147 阅读 · 0 评论 -
python—删除链表中倒数第K个元素
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next# 顺序删除def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode: dummy = ListNode(0) dummy.next = head # step1: 获取链表长度 cur原创 2021-02-25 07:10:24 · 404 阅读 · 0 评论 -
python—找出单链表中倒数第K个元素
class LNode(object): def __init__(self, item): self.data = item self.next = Nonedef findLastK(head, k): if head is None or head.next is None: return slow = LNode() fast = LNode() slow = head.next fast = he原创 2021-02-25 07:09:27 · 167 阅读 · 0 评论 -
python—从单链表中移除重复项
class LNode(object): def __init__(self, item): self.data = item self.next = None# 顺序删除 时间复杂度 o(n**2)def removeDup(head): if head == None or head.next == None: return outerCur = head.next interCur = None int原创 2021-02-25 07:07:43 · 574 阅读 · 0 评论 -
python—单链表反转
def reverseList(head): if head is None or head.next is None: return head pre_node = head current_node = head while current_node is not None: next_node = current_node.next # 暂存当前节点的next节点 current_node.next = pre_node # 当前节点的next指向初始化的节点 pre_n原创 2021-02-25 07:02:27 · 104 阅读 · 0 评论 -
python—创建单向链表及操作
文章目录概述概述我们将在接下来的章节中介绍更多内容。完成后,你将:了解单链表和双链表的结构;在单链表或双链表中实现遍历、插入和删除;分析在单链表或双链表中的各种操作的复杂度;在链表中使用双指针技巧(快指针慢指针技巧);解决一些经典问题,例如反转链表;分析你设计的算法的复杂度;积累设计和调试的经验。...原创 2021-02-25 06:46:08 · 197 阅读 · 0 评论