Yanir7 2019-03-27 19:56 采纳率: 0%
浏览 4351
已采纳

几行python代码消耗将近20g内存,电脑跑崩了?pydev debugger: process 15180 is connecting

pycharm报错:pydev debugger: process 15180 is connecting

代码如下:

# 给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。
#
# 示例:
#
# 给定一个链表: 1->2->3->4->5, 和 n = 2.
#
# 当删除了倒数第二个节点后,链表变为 1->2->3->5.
# 
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
        # p=head
        # q=p
        # count=0
        # if not head.val:return None
        # while q:
        #     count+=1
        #     q=q.next
        # if n>count:return None
        # n=count-n+1
        # if n==1:
        #     head=p.next
        #     return head
        # for i in range(n-2):
        #     p=p.next
        # des=p.next
        # p.next=des.next
        # return head
        p1, p2 = head, head
        while n:
            p2 = p2.next
            n -= 1
        # if the n=len(list)
        if not p2:
            return head.next
        while p2.next:
            p2 = p2.next
            p1 = p1.next
        tmp = p1.next.next
        p1.next = tmp
        return head
if __name__=='__main__':
    head=ListNode(1)
    p=head
    i=2
    while i<6:
        p.next=ListNode(i)
        p=p.next
    p.next=None
    solution=Solution()
    solution.removeNthFromEnd(head)
    p=head
    while p:
        print(p.val)
        p=p.next








  • 写回答

1条回答 默认 最新

  • Yanir7 2019-03-27 20:18
    关注

    是我太年轻了,删帖,问题有点愚蠢~~

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog