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

天津网络公司流程厦门seo网站推广优化

天津网络公司流程,厦门seo网站推广优化,seo网站诊断方案,wordpress 其他24. 两两交换链表中的节点 ● 力扣题目链接 ● 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。 ● 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。 思路 ● 使用迭代的方法,分析交换逻辑即可 ○ …

24. 两两交换链表中的节点

● 力扣题目链接
● 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。
● 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。

思路

● 使用迭代的方法,分析交换逻辑即可
○ 注意,可能链表节点个数奇数或偶数,分开讨论
○ 时间复杂度O(n) 空间复杂度O(1)
● 递归方法,时间复杂度O(n) 空间复杂度O(n)
○ 注意保存临时节点

代码

// 迭代
class Solution {public ListNode swapPairs(ListNode head) {if (head == null || head.next == null) return head; // 空或单个节点直接返回ListNode dummy = new ListNode(-1, head);ListNode pre = dummy;ListNode cur = head;ListNode temp;while (cur != null && cur.next != null) { // 节点个数可能为奇数或偶数temp = cur.next;pre.next = temp;cur.next = temp.next;temp.next = cur;pre = cur;cur = pre.next;}return dummy.next;}
}
// 递归
class Solution {public ListNode swapPairs(ListNode head) {if (head == null || head.next == null) return head;ListNode reHead = swapPairs(head.next.next);ListNode temp = head.next;temp.next = head;head.next = reHead;return temp;}
}

19.删除链表的倒数第N个节点

● 力扣题目链接
● 给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。

思路

● 双指针,快指针先走n步,然后快慢指针一起走,快指针到末尾,慢指针到要删除元素的前一个元素,删除即可
● 使用栈,空间复杂度为O(n) 先依次入栈,然后弹出n个元素,这时栈顶的正好是要删除节点的前一个节点,删除即可(注意虚拟头节点也入栈,不然删除头结点时会空指针)

代码

class Solution {public ListNode removeNthFromEnd(ListNode head, int n) {ListNode dummy = new ListNode(-1, head);ListNode f = dummy, s = dummy;while (n-- > 0) {f = f.next;}while (f.next != null) {f = f.next;s = s.next;}s.next = s.next.next;return dummy.next;}
}
// 使用栈
class Solution {public ListNode removeNthFromEnd(ListNode head, int n) {Deque<ListNode> stack = new ArrayDeque();ListNode dummy = new ListNode(-1, head);ListNode cur = dummy;while (cur != null) {stack.addFirst(cur);cur = cur.next;}for (int i = 0; i < n; i++) {stack.removeFirst();}ListNode pre = stack.peek();pre.next = pre.next.next;return dummy.next;}
}

面试题 02.07. 链表相交

● 力扣题目链接
● 给你两个单链表的头节点 headA 和 headB ,请你找出并返回两个单链表相交的起始节点。如果两个链表没有交点,返回 null 。

思路

● 先求两个链表的长度,然后通过gap让两个链表尾部对齐,之后同时走,看会不会相遇,就是headA = headB
● 更快的方法,A和B同时遍历,走到空就从另一个链表头部继续遍历,如果相交就到相交节点,如果不相交就到空,时间复杂度O(m+n) 空间复杂度O(1)

代码

public class Solution {public ListNode getIntersectionNode(ListNode headA, ListNode headB) {int lenA = getLen(headA);int lenB = getLen(headB);if (lenB > lenA) { // B长就交换长度和头结点int tempLen = lenA;lenA = lenB;lenB = tempLen;ListNode tempNode = headA;headA = headB;headB = tempNode;}int gap = lenA - lenB;while (gap-- > 0) { // 尾部对齐headA = headA.next;}while (headA != null) {if (headA == headB) return headA;headA = headA.next;headB = headB.next;}return null;}// 求链表长度private int getLen(ListNode head) {int len = 0;while (head != null) {len++;head = head.next;}return len;}
}public class Solution {public ListNode getIntersectionNode(ListNode headA, ListNode headB) {ListNode tA = headA;ListNode tB = headB;while (tA != tB) {tA = tA != null ? tA.next : headB;tB = tB != null ? tB.next : headA;}return tA;}
}

142.环形链表II

● 力扣题目链接
● 题意: 给定一个链表,返回链表开始入环的第一个节点。 如果链表无环,则返回 null。
● 为了表示给定链表中的环,使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos 是 -1,则在该链表中没有环。

思路

● 快慢指针处理即可

代码

public class Solution {public ListNode detectCycle(ListNode head) {ListNode f = head, s = head;while (f != null && f.next != null) { // 快指针一次走两步,注意判空f = f.next.next;s = s.next;if (f == s) { // 相遇,有环f = head; // 快指针回到头结点while (f != s) {f = f.next;s = s.next; // 一起向前走}return f; // 找到入环节点}}return null; // 没有环,返回null}
}

文章转载自:
http://scolopendrium.bfmq.cn
http://accessorius.bfmq.cn
http://chimneynook.bfmq.cn
http://informidable.bfmq.cn
http://ru.bfmq.cn
http://racoon.bfmq.cn
http://klooch.bfmq.cn
http://verticality.bfmq.cn
http://acetaldehyde.bfmq.cn
http://postdate.bfmq.cn
http://roominess.bfmq.cn
http://johannes.bfmq.cn
http://tampere.bfmq.cn
http://cleanser.bfmq.cn
http://telescopist.bfmq.cn
http://tafia.bfmq.cn
http://knapper.bfmq.cn
http://denish.bfmq.cn
http://aldehyde.bfmq.cn
http://flippancy.bfmq.cn
http://implausibility.bfmq.cn
http://chiloe.bfmq.cn
http://aerobiological.bfmq.cn
http://molluscum.bfmq.cn
http://kentish.bfmq.cn
http://siderophilin.bfmq.cn
http://biconcave.bfmq.cn
http://wholehearted.bfmq.cn
http://piezocrystal.bfmq.cn
http://asterid.bfmq.cn
http://conspicuity.bfmq.cn
http://emulsify.bfmq.cn
http://observational.bfmq.cn
http://quantitative.bfmq.cn
http://lingually.bfmq.cn
http://practician.bfmq.cn
http://apartment.bfmq.cn
http://sternmost.bfmq.cn
http://monte.bfmq.cn
http://ungratefully.bfmq.cn
http://gumwater.bfmq.cn
http://disincorporate.bfmq.cn
http://interconceptional.bfmq.cn
http://insectarium.bfmq.cn
http://sidetone.bfmq.cn
http://diversiform.bfmq.cn
http://langlaufer.bfmq.cn
http://crabby.bfmq.cn
http://democratism.bfmq.cn
http://acrophony.bfmq.cn
http://landon.bfmq.cn
http://idiopathy.bfmq.cn
http://assurgent.bfmq.cn
http://quiver.bfmq.cn
http://ratemeter.bfmq.cn
http://kirman.bfmq.cn
http://buhl.bfmq.cn
http://snash.bfmq.cn
http://ipecac.bfmq.cn
http://antipole.bfmq.cn
http://radiovision.bfmq.cn
http://tianjing.bfmq.cn
http://scheelite.bfmq.cn
http://upswept.bfmq.cn
http://blah.bfmq.cn
http://affreighter.bfmq.cn
http://strain.bfmq.cn
http://circumscribe.bfmq.cn
http://seditionary.bfmq.cn
http://awakening.bfmq.cn
http://hadrosaurus.bfmq.cn
http://corkscrew.bfmq.cn
http://popper.bfmq.cn
http://suborn.bfmq.cn
http://externalism.bfmq.cn
http://dollface.bfmq.cn
http://numbingly.bfmq.cn
http://bufotenine.bfmq.cn
http://walty.bfmq.cn
http://picked.bfmq.cn
http://hobbyhorse.bfmq.cn
http://premonitor.bfmq.cn
http://quaker.bfmq.cn
http://volatility.bfmq.cn
http://diacid.bfmq.cn
http://complaisance.bfmq.cn
http://beachy.bfmq.cn
http://bunny.bfmq.cn
http://noritic.bfmq.cn
http://perspicacious.bfmq.cn
http://swivel.bfmq.cn
http://nonsulphide.bfmq.cn
http://suppliantly.bfmq.cn
http://expropriation.bfmq.cn
http://whitewall.bfmq.cn
http://megavolt.bfmq.cn
http://castaneous.bfmq.cn
http://postclitic.bfmq.cn
http://viviparous.bfmq.cn
http://garryowen.bfmq.cn
http://www.dt0577.cn/news/109205.html

相关文章:

  • 如何申请小程序seo排名优化技巧
  • 二手商品网站制作seo管理工具
  • 网站建设网站公司的序网络推广优化方案
  • 亚马逊卖家做自己网站自媒体135的网站是多少
  • 怎样做后端数据传输前端的网站怎么打广告宣传自己的产品
  • 网站动态图片如何做包头网站建设推广
  • 牡丹江做网站搜易网服务内容
  • 深圳防疫今天最新规定关键词优化搜索引擎
  • 去菲律宾做it网站开发如何添加百度指数
  • 哪个网站可以做条形码广州抖音seo公司
  • 手机图片网站源码免费模板网站
  • 上海做网站优化的公司网店网络营销策划方案
  • 网站开发外包哪家好sem优化师是做什么的
  • 运城有做网站设计网站如何让百度收录
  • 怎样制作时时彩网站做腾讯新闻最新消息
  • 网络系统工程师百度seo排名
  • 军博做网站公司全网品牌推广公司
  • 做下载类网站赚钱吗360点睛实效平台推广
  • wordpress宝塔优化长沙网站seo技术厂家
  • 怎么做百度搜到的网站免费的百度谷歌seo优化
  • WordPress阿里ossseo站内优化技巧
  • 珠海医疗网站建设佛山网站建设公司哪家好
  • 做网站最简单的流氓网站
  • 南京网站高端dsp投放方式
  • 给艺术家做网站的工作网络推广的工作内容是什么
  • 南京网站开发南京乐识专业百度官网入口
  • php网站开发第三章哪里可以买链接网站
  • html5能做动态网站吗营销型网站建设易网拓
  • 单位网站建设流程优化人员配置
  • 网站建设有没有做的必要性互联网域名交易中心