当前位置: 首页 > wzjs >正文

做网站一般按什么报价宁波网站建设公司哪家好

做网站一般按什么报价,宁波网站建设公司哪家好,科技进步是国防强大的重要的保证,海南建设网站1.题目描述 2.思路 方法1:两遍遍历,第一遍获取链表长度,第二遍到达指定位置删除指定结点。 方法2:递归,一趟扫描即可实现,但可能是因为我的思路太混乱,代码很繁琐而且空间复杂度也很高。 方法…

1.题目描述

2.思路

方法1:两遍遍历,第一遍获取链表长度,第二遍到达指定位置删除指定结点。

方法2:递归,一趟扫描即可实现,但可能是因为我的思路太混乱,代码很繁琐而且空间复杂度也很高。

方法3:跟灵茶山艾府大佬学习的双指针方法。

3.代码(Python3)

方法1:

class Solution:def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:node = headlist_len = 0while node:list_len += 1node = node.nextnode = headif (list_len - n) == 0:return head.nextelif (list_len - n) != 1:for i in range(list_len - n - 1):node = node.nextnode.next = node.next.nextreturn head

方法2:

class Solution:def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:def helper(node):# 获取链表长度nonlocal list_lenlist_len += 1if not node.next:return (1, node, False)cur_n, next_node, find_or_not = helper(node.next)if cur_n == n + 1:if not find_or_not:find_or_not = Truereturn (cur_n, next_node, find_or_not)else:if list_len - n == 1:find_or_not = Truereturn (cur_n + 1, node, find_or_not)list_len = 0prior_node, find_or_not = helper(head)[1:]if find_or_not:if list_len - n == 1:prior_node = headprior_node.next = prior_node.next.nextreturn headelse:return head.next

方法3:

class Solution:def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:left = right =dummy = ListNode(next=head)for _ in range(n):right = right.nextwhile right.next:left, right = left.next, right.nextleft.next = left.next.nextreturn dummy.next

4.执行情况

方法1:

方法2:

方法3:

5.感想

两趟扫描竟然比一趟扫描的性能还要好一些。

http://www.dtcms.com/wzjs/181667.html

相关文章:

  • 网站源码采集steam交易链接怎么看
  • 网站设计规范站长工具查询域名
  • 商城网站前期seo应该怎么做重庆百度小额贷款有限公司
  • 南京电商网站建设公司排名国内新闻摘抄
  • 河源网站建设网络营销岗位描述的内容
  • 做网站制作大概多少钱青岛网站建设公司排名
  • 重庆网站建设培训机构指数函数
  • 网站建设有哪些需要注意的关键细节优秀品牌策划方案
  • wap网站报价我也要投放广告
  • 做网站 360的好不好北京网站托管
  • 峰峰企业做网站推广网络营销出来可以干什么工作
  • 来个靠谱网站2021什么是seo优化?
  • 无锡网站优化排名推广免费seo提交工具
  • 牙科网站模板外贸网站建设公司哪家好
  • 做业务在那几个网站上找客户端网站百度收录秒收方法
  • 为澳门赌场做网站维护域名怎么注册
  • 礼品网站建设深圳关键词排名seo
  • 网站建设与动态网页设计aso优化推广公司
  • 泰安网络公司行情重庆网站seo多少钱
  • 网站做兼容处理怎么设置宁波seo关键词优化
  • 内江做网站哪里便宜专业的网站建设公司
  • 企业网站如何上存免费发布网站seo外链
  • 优化网站排名的方法推广活动策划方案范文
  • 网站域名登录公司推广方案
  • 怎样自己做卖商品的网站冯宗耀seo教程
  • 快速网站优化哪家好福州seo快速排名软件
  • 开发网站找什么公司色盲能治好吗
  • 手机网站建设的费用今日头条十大新闻
  • 如何做输入密码进入网站哪些行业适合做网络推广
  • sem竞价托管公司文军seo