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

SouthLeetCode-打卡24年01月第5周

SouthLeetCode-打卡24年01月第5周

// Date : 2024/01/39 ~ 2024/01/31

031.删除链表的倒数第 N 个结点

(1) 题目描述

031#LeetCode.19.#北岸计划2024/01/29

(2) 题解代码

Version1.0

class Solution {public ListNode removeNthFromEnd(ListNode head, int n) {if(head == null){ return null; }ListNode dummy = new ListNode();dummy.next = head;ListNode prev = dummy;ListNode curr = head;ListNode stker = head;for(int i=0 ; i<n ; i++){stker = stker.next;}while(stker != null){prev = prev.next;curr = curr.next;stker = stker.next;}if(curr == null){prev.next = null;}else{prev.next = curr.next;}return dummy.next;}
}

(3) 题目描述

  • Version1.0版本中,实践了无脑思路:1.链表转数组 2.操作数组 3.数组转链表 .

032.相交链表

(1) 题目描述

032#LeetCode.160.#北岸计划2024/01/30

给你两个单链表的头节点 headAheadB ,请你找出并返回两个单链表相交的起始节点。

如果两个链表不存在相交节点,返回 null

(2) 题解代码

public class Solution {ListNode getIntersectionNodeHelper(ListNode curr1, ListNode curr2,ListNode head1, ListNode head2){curr2 = head1;while(curr1 != null){curr1 = curr1.next;curr2 = curr2.next;}curr1 = curr2;curr2 = head2;while(curr1 != curr2){curr1 = curr1.next;curr2 = curr2.next;}return curr1;}public ListNode getIntersectionNode(ListNode headA, ListNode headB) {ListNode currA = headA;ListNode currB = headB;while(currA != null && currB != null){currA = currA.next;currB = currB.next;}if(currA != null){return getIntersectionNodeHelper(currA,currB,headA,headB);}else{return getIntersectionNodeHelper(currB,currA,headB,headA);}}
}

033.环形链表Ⅱ

(1) 题目描述

033#LeetCode.142.#北岸计划2024/01/31

给定一个链表的头节点 head ,返回链表开始入环的第一个节点。 如果链表无环,则返回 null

如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环。

为了表示给定链表中的环,评测系统内部使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。

如果 pos-1,则在该链表中没有环。注意:pos 不作为参数进行传递,仅仅是为了标识链表的实际情况。

不允许修改 链表。

(2) 题解代码

public class Solution {public ListNode detectCycle(ListNode head) {ListNode dummy = new ListNode();dummy.next = head;ListNode slow = dummy;ListNode fast = dummy;boolean isCycle  = false;while(fast != null){slow = slow.next;fast = fast.next;if(fast != null){fast = fast.next;isCycle = fast == slow ? true : false;}if(isCycle) break;}if(isCycle){fast = dummy;while(slow != fast){slow = slow.next;fast = fast.next;}}return fast;}
}
http://www.lryc.cn/news/292804.html

相关文章:

  • 【国产MCU】-CH32V307-通用DMA控制器及使用
  • mysql8.0-cnf文件
  • MySQL进阶45讲【11】怎么更好地给字符串字段加索引?
  • ​(三)hadoop之hive的搭建1
  • Spring事务传播机制
  • 智能分析网关V4+EasyCVR视频融合平台——高速公路交通情况的实时监控和分析一体化方案
  • Vue3.0(一):Vue的引入-options api-模板语法
  • API网关-Apisix多节点搭建(RPM包方式)
  • HAL库配置片内FLASH读写
  • 日志记录——单片机可执行文件合并
  • 2024数模美赛C题F题完整代码结果展示
  • H5调用安卓原生相机API案例
  • Java面试——计网篇
  • 函数式接口当参数使用
  • 全面详解Maven的配置文件settings.xml
  • 【Spring连载】使用Spring Data访问Redis(十四)----Redis Repositories
  • 小鹏汽车穿越“生死线”
  • AIPC专题:深耕笔电背光模组领域,AIPC与车载显示拉动公司成长
  • 架构(十一)从0到1实现动态定时任务
  • Mybatis 批量插入数据 SQL
  • 【学员分享-考试心得】国产数据库潜力无限,云贝教育OBCP认证培训帮您解难题
  • 【Mysql】事务的隔离级别与 MVCC
  • MongoDB从入门到实战之MongoDB快速入门
  • Linux服务详解
  • 闲聊电脑(4)硬盘分区
  • 光耦合器的结构与原理解析
  • 代码随想录day17--二叉树的应用5
  • 跟着cherno手搓游戏引擎【19】抽象纹理
  • CentOS 7中搭建NFS文件共享服务器的完整步骤
  • 【华为OD机试】 最小矩阵宽度【2024 C卷|100分】