- 博客(5)
- 收藏
- 关注
原创 matplotlib作图
import matplotlib.pyplot as pltdef autolabel(rects): for rect in rects: height = rect.get_height() plt.text(rect.get_x()+rect.get_width()/2.-0.25, 1.01*height, '%s' % float(height), ha='left')name_list = ['1', '2', '3', '4']num_l.
2022-01-01 15:57:59 1745
原创 链表“两个”“多个”-python解法总结
两个链表相交的起始节点链接class Solution(object): def getIntersectionNode(self, headA, headB): p1=headA #双指针 分别在两条链表上行走 p2=headB while p1 != p2: #指针先在自己的链表上遍历,遍历完遍历另一条链表 p1=p1.next if p1 else headB .
2021-09-06 22:47:41 201
原创 链表“倒数”-python算法总结
思路:快慢指针,快指针先走k步链表中倒数最后k个节点链接class Solution: def FindKthToTail(self , pHead , k ): fast=pHead slow=pHead for i in range(k): if not fast: #如果链表长度小于k返回None return None fast=fast.next
2021-09-06 14:18:03 133
原创 链表“环”-python解法总结
判断链表中是否有环链接思路:快慢指针class Solution: def hasCycle(self , head ): fast=head #快指针一次走两步 slow=head #慢指针一次走一步 while fast and fast.next: fast=fast.next.next slow=slow.next if fast==slow: #如果有环快慢
2021-09-06 13:43:13 159
原创 链表“反”-python解法总结
反转链表链接思路:双指针class Solution: def ReverseList(self, pHead): pre=None #pre指针记录当前结点点的前一个结点 cur=pHead while cur: tmp=cur.next cur.next=pre #当前结点的next指针改为指向前一个结点进行反转 pre=cur #pre和cur指针向前移动
2021-09-06 12:22:39 92
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人