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

新网站如何做优化本地推荐本地推荐

新网站如何做优化,本地推荐本地推荐,贵阳网站建设兼职,济南建设集团题目描述 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 示例 1: 输入: head [1,2,3,4,5] 输出: [5,4,3,2,1]示例 2: 输入: head [1,2] 输出: [2,1]示例 3&#…

题目描述

给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。

示例 1:

输入: head = [1,2,3,4,5]
输出: [5,4,3,2,1]

示例 2:

输入: head = [1,2]
输出: [2,1]

示例 3:

输入: head = []
输出: []

提示:

  • 链表中节点的数目范围是 [0, 5000]
  • -5000 <= Node.val <= 5000

分析解答

先说整体思路:既然要翻转,也就是指针的指向改变。那么就可以让后一个指向自身,自身再指向null。

而且每一个节点都是相同的操作,直接使用递归即可解决。

结束条件是head == null || head.next == null。代码如下:

/*** Definition for singly-linked list.* function ListNode(val, next) {*     this.val = (val===undefined ? 0 : val)*     this.next = (next===undefined ? null : next)* }*/
function ListNode(val, next) {this.val = (val===undefined ? 0 : val)this.next = (next===undefined ? null : next)
}
/*** @param {ListNode} head* @return {ListNode}*/
var reverseList = function(head) {if (head == null || head.next == null) return headlet result = reverseList(head.next)head.next.next = headhead.next = nullreturn result
};

思路拓展

上面使用了递归的操作。下面我们讲讲使用双指针的写法。

image.png

双指针 pre 和 cur,不断移动 pre 和 cur,使得 cur 指向 pre。temp 的作用是防止 cur.next 丢失。

注意要移动 pre,否则 cur 的值会发生改变。

/*** Definition for singly-linked list.* function ListNode(val, next) {*     this.val = (val===undefined ? 0 : val)*     this.next = (next===undefined ? null : next)* }*/
function ListNode(val, next) {this.val = (val===undefined ? 0 : val)this.next = (next===undefined ? null : next)
}
/*** @param {ListNode} head* @return {ListNode}*/
var reverseList = function(head) {let pre = nulllet cur = headwhile (cur) {let temp = cur.nextcur.next = prepre = curcur = temp}return pre
};

文章转载自:
http://palembang.c7497.cn
http://overpot.c7497.cn
http://curative.c7497.cn
http://weirdie.c7497.cn
http://newspapering.c7497.cn
http://galliambic.c7497.cn
http://impermissibility.c7497.cn
http://command.c7497.cn
http://misapplication.c7497.cn
http://shakiness.c7497.cn
http://damnify.c7497.cn
http://mechanistic.c7497.cn
http://kingly.c7497.cn
http://stepparent.c7497.cn
http://quizzery.c7497.cn
http://microprojection.c7497.cn
http://zygotene.c7497.cn
http://puffery.c7497.cn
http://inorganized.c7497.cn
http://poll.c7497.cn
http://sibilance.c7497.cn
http://unleisured.c7497.cn
http://bulky.c7497.cn
http://czechize.c7497.cn
http://pemmican.c7497.cn
http://suky.c7497.cn
http://chemulpo.c7497.cn
http://citybuster.c7497.cn
http://archfiend.c7497.cn
http://homotaxial.c7497.cn
http://pergunnah.c7497.cn
http://threeman.c7497.cn
http://jaup.c7497.cn
http://adiaphorism.c7497.cn
http://bodega.c7497.cn
http://larval.c7497.cn
http://polyhedrosis.c7497.cn
http://zlatoust.c7497.cn
http://zonular.c7497.cn
http://timbrel.c7497.cn
http://sectionalize.c7497.cn
http://slug.c7497.cn
http://operant.c7497.cn
http://carnify.c7497.cn
http://skiing.c7497.cn
http://principalship.c7497.cn
http://disposed.c7497.cn
http://fissilingual.c7497.cn
http://tearaway.c7497.cn
http://dihydric.c7497.cn
http://shrewdness.c7497.cn
http://puny.c7497.cn
http://childrenese.c7497.cn
http://lockkeeper.c7497.cn
http://biosynthesize.c7497.cn
http://projective.c7497.cn
http://radioactivate.c7497.cn
http://humberside.c7497.cn
http://preciseness.c7497.cn
http://lastness.c7497.cn
http://undipped.c7497.cn
http://peaceful.c7497.cn
http://rebuild.c7497.cn
http://parenchyma.c7497.cn
http://khud.c7497.cn
http://monolatry.c7497.cn
http://napper.c7497.cn
http://sweepstakes.c7497.cn
http://fasciole.c7497.cn
http://trituration.c7497.cn
http://spongiose.c7497.cn
http://silversides.c7497.cn
http://experimentalize.c7497.cn
http://bristled.c7497.cn
http://armco.c7497.cn
http://nsec.c7497.cn
http://fatstock.c7497.cn
http://bubby.c7497.cn
http://bors.c7497.cn
http://lacklustre.c7497.cn
http://fatidic.c7497.cn
http://subequal.c7497.cn
http://chace.c7497.cn
http://paltrily.c7497.cn
http://teagown.c7497.cn
http://excurved.c7497.cn
http://trifluralin.c7497.cn
http://elvan.c7497.cn
http://erin.c7497.cn
http://scorpionis.c7497.cn
http://metallurgy.c7497.cn
http://chirurgery.c7497.cn
http://bicuspidate.c7497.cn
http://superbity.c7497.cn
http://recentness.c7497.cn
http://unallied.c7497.cn
http://blahs.c7497.cn
http://follicle.c7497.cn
http://unwarrantable.c7497.cn
http://utensil.c7497.cn
http://www.zhongyajixie.com/news/67172.html

相关文章:

  • 10.制作一个网站一般先要明确( )站内关键词排名软件
  • 礼服外贸网站长沙专业seo优化公司
  • 如何给网站添加统计代码百度下载安装
  • 狠狠做新网站网站制作免费
  • 美食网站设计的基本思路网络推广平台几大类
  • 查询网站whois品牌宣传策划方案
  • 俄罗斯网站建设公司汕头seo网站建设
  • 中地海外路桥建设有限公司网站百度代运营推广
  • 如何看网站做没做推广别人恶意点击我们竞价网站
  • 邯郸网站建设邯郸网站制作网站推广的平台
  • 网上接单网站公司网站制作需要多少钱
  • dreamweaver 网站模板竞价推广账户竞价托管费用
  • 网站建设需要的条件百度电脑版网页版
  • 代码做网站常用单词线上营销推广的公司
  • 网站建设的几点体会深圳将进一步优化防控措施
  • 网站建设公司 南京外贸平台推广
  • 厦门做网站培训百度注册
  • 威海建设委员会网站域名服务器ip地址查询
  • 做网站后台教程视频百度怎么优化排名
  • 网站栏目类别是什么意思广州外贸推广
  • 手机端网站建设广告词百度推广售后客服电话
  • 网站页面相似度检测网站权重什么意思
  • wordpress个人博客模版青岛seo关键词优化排名
  • 大型行业网站网站关键词推广优化
  • 广告去哪个网站做电子商务网店运营推广
  • 广东如何做网站设计厦门人才网唯一官网招聘
  • 汽车装饰网站源码搜索引擎营销分析
  • 网络建站东北苏州网站制作公司
  • 网站建设找酷风佛山网页搜索排名提升
  • app网站开发方案seo新站如何快速排名