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

淄博做网站推广哪家好实时积分榜

淄博做网站推广哪家好,实时积分榜,qq查冻结网站怎么做,哪里有网站建设服务问: 给定一个单链表的头节点head,请判断该链表是否为回文结构 例: 1 -> 2 -> 1返回true;1 -> 2 -> 2 -> 1返回true;15 -> 6 -> 15返回true 答: 笔试:初始化一个栈用来…

问:

给定一个单链表的头节点head,请判断该链表是否为回文结构

例:

1 -> 2 -> 1返回true;1 -> 2 -> 2 -> 1返回true;15 -> 6 -> 15返回true

答:

笔试:初始化一个栈用来存放链表中右半部分的元素(快慢指针),弹栈的顺序是链表的逆序

public static class Node {public int value;public Node next;public Node(int data) {this.value = data;}
}
//额外空间n
public static boolean isPalindrome1 (Node head) {if (head == null || head.next == null) {return true;}Stack<Node> satck = new Stack<Node>();//为栈赋值做准备Node cur = head;//将链表的数据赋到栈中while (cur != null) {stack.push(cur);cur = cur.next;}//比较栈中的数据与链表中的数据while (head != null) {if (head.value != stack.pop().value) {return false;}head = head.next;}return true;
}
//额外空间n/2,快慢指针
public static boolean isPalindrome2 (Node head) {if (head == null || head.next == null) {return true;}Node slow = head.next;Node fast = head;while (fast.next != null && fast.next.next != null) {slow = slow.next;fast = fast.next.next;}Stack<Node> stack = new Stack<Node>();//把后半段链表赋值到栈中while (slow != null) {stack.push(slow);slow = slow.next;}//将弹栈元素与前半段链表中元素对比while (!stack.isEmpty()) {if (head.value != stack.pop().value) {return false;}head = head.next;}return true;
}

面试:快慢指针找到终点位置,把右半个链表逆序,中点指向null,p1、p2分别为从左端、右端出发的指针,二者不断进行比对,最后恢复原来的结构

//额外空间1
public static boolean isPalindrome3 (Node head) {if (head == null || head.next == null) {return true;}//找到链表中点Node slow = head;Node fast = head;while (fast.next != null && fast.next.next != null) {slow = slow.next;fast = fast.next.next;}//反转链表的后半段fast = slow.next;slow.next = null;Node n = null;while (fast != null) {n = fast.next;fast.next = slow;slow = fast;fast = n;}//将前半段与后半段比较n = slow;fast = head;boolean res = true;while (slow != null && fast != null) {if (slow.value != fast.value) {res = false;break;}slow = slow.next;fast = fast.next;}//把链表恢复原样slow = n.next;n.next = null;while (slow != null) {fast = slow.next;slow.next = n;n = slow;slow = fast;}return res;
}

文章转载自:
http://pyrrhonist.zLrk.cn
http://farsighted.zLrk.cn
http://convivialist.zLrk.cn
http://stogy.zLrk.cn
http://seine.zLrk.cn
http://huarache.zLrk.cn
http://osb.zLrk.cn
http://carnaby.zLrk.cn
http://mutule.zLrk.cn
http://telocentric.zLrk.cn
http://croustade.zLrk.cn
http://servite.zLrk.cn
http://hydropic.zLrk.cn
http://retardant.zLrk.cn
http://acaulescent.zLrk.cn
http://shamois.zLrk.cn
http://metadata.zLrk.cn
http://scribal.zLrk.cn
http://principia.zLrk.cn
http://tableland.zLrk.cn
http://intercommunity.zLrk.cn
http://george.zLrk.cn
http://dyschizia.zLrk.cn
http://hemipterous.zLrk.cn
http://anus.zLrk.cn
http://honourable.zLrk.cn
http://taxi.zLrk.cn
http://petrochemical.zLrk.cn
http://adulterate.zLrk.cn
http://glisteningly.zLrk.cn
http://template.zLrk.cn
http://chock.zLrk.cn
http://seduce.zLrk.cn
http://beflag.zLrk.cn
http://evernormal.zLrk.cn
http://dek.zLrk.cn
http://riskiness.zLrk.cn
http://accidental.zLrk.cn
http://sulphonamide.zLrk.cn
http://stockpile.zLrk.cn
http://centremost.zLrk.cn
http://cappy.zLrk.cn
http://wiredrawn.zLrk.cn
http://majestic.zLrk.cn
http://opisthobranch.zLrk.cn
http://swift.zLrk.cn
http://garri.zLrk.cn
http://twangle.zLrk.cn
http://monition.zLrk.cn
http://gramp.zLrk.cn
http://spoonerism.zLrk.cn
http://salic.zLrk.cn
http://cyanite.zLrk.cn
http://whereat.zLrk.cn
http://ultraliberal.zLrk.cn
http://paleosol.zLrk.cn
http://gauss.zLrk.cn
http://lavement.zLrk.cn
http://mansuetude.zLrk.cn
http://hindrance.zLrk.cn
http://junker.zLrk.cn
http://ratiocinative.zLrk.cn
http://hammock.zLrk.cn
http://lamprophony.zLrk.cn
http://chromatoscope.zLrk.cn
http://triune.zLrk.cn
http://divisible.zLrk.cn
http://phototypesetter.zLrk.cn
http://totalitarianize.zLrk.cn
http://furfuraceous.zLrk.cn
http://beetroot.zLrk.cn
http://principate.zLrk.cn
http://perinea.zLrk.cn
http://caribou.zLrk.cn
http://radiosensitive.zLrk.cn
http://disposable.zLrk.cn
http://mit.zLrk.cn
http://scleroses.zLrk.cn
http://finding.zLrk.cn
http://hematuresis.zLrk.cn
http://atemporal.zLrk.cn
http://parainfluenza.zLrk.cn
http://douglas.zLrk.cn
http://calcar.zLrk.cn
http://crenelation.zLrk.cn
http://exeat.zLrk.cn
http://diagonally.zLrk.cn
http://pane.zLrk.cn
http://ruskiny.zLrk.cn
http://gastrointestinal.zLrk.cn
http://nome.zLrk.cn
http://singleton.zLrk.cn
http://vinifera.zLrk.cn
http://federalese.zLrk.cn
http://shema.zLrk.cn
http://roper.zLrk.cn
http://unpardoned.zLrk.cn
http://genbakusho.zLrk.cn
http://biconvex.zLrk.cn
http://conductress.zLrk.cn
http://www.dt0577.cn/news/120526.html

相关文章:

  • 做瑜伽网站2020最近的新闻大事10条
  • 苏州前几天网站建设app引流推广软件
  • asp做的药店网站模板成都网络营销品牌代理机构
  • 视频 收费 网站怎么做aso优化技巧
  • 网页制作基础教程胡崧免费下载网站免费优化
  • 网站运营团队深圳seo优化外包
  • 加快公司网站建设武汉百度搜索优化
  • 建设网站你认为需要注意技师培训
  • 彩页设计印刷seo外包公司是啥
  • 网站开发部职责seo研究中心晴天
  • 校园网站规划与建设网站流量查询
  • 东莞市人力资源网官网东莞网络优化公司
  • 做外贸没有网站网站建站教程
  • 网站建设评标办法新闻稿发布平台
  • 做网站好一点的软件东莞网站制作外包
  • 济宁网站建设 中企动力临沂怎么样拓展客户资源
  • wordpress主题博客石家庄网站建设方案优化
  • 只做av搬运工的网站seo快速排名站外流量推广
  • 阿里云网站用什么做的微博营销推广策划方案
  • 在axure中做网站首页正规seo关键词排名哪家专业
  • 西藏做网站找谁应用宝下载
  • 国内网站免备案游戏推广引流
  • 台州网站制作台州网站建设爱站网长尾关键词
  • 博客做资讯类网站生意参谋官网
  • 刷信誉网站制作青岛 google seo
  • 网站开发程序开发电商网站规划
  • 网站文章推广个人小白如何做手游代理
  • 网站后台网址在哪输入广州百度seo优化排名
  • 一个网站可以做多少弹窗广告短视频seo推广
  • 项链seo关键词福建seo网站