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

力扣labuladong——一刷day02

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、力扣876. 链表的中间结点
  • 二、力扣142. 环形链表 II
  • 三、力扣160. 相交链表
  • 四、力扣141. 环形链表


前言


一、力扣876. 链表的中间结点

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode middleNode(ListNode head) {ListNode res = new ListNode(-1,head);ListNode p = head;int len = 0;while(p != null){p = p.next;len ++;}int i = len / 2 + 1;p = head;for(int j = 1; j < i; j ++){p = p.next;}return p;}
}

快慢指针遍历一次

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode middleNode(ListNode head) {ListNode dump = new ListNode(-1,head);ListNode p1 = dump, p2 = dump;for(; p2 != null;){p1 = p1.next;p2 = p2.next;if(p2 == null){return p1;}p2 = p2.next;}return p1;}
}

二、力扣142. 环形链表 II

/*** Definition for singly-linked list.* class ListNode {*     int val;*     ListNode next;*     ListNode(int x) {*         val = x;*         next = null;*     }* }*/
public class Solution {public ListNode detectCycle(ListNode head) {ListNode p1 = head, p2 = head;while(p1 != null && p2 != null && p2.next != null){p1 = p1.next;p2 = p2.next.next;if(p1 == p2){p1 = head;while(p1 != p2){p1 = p1.next;p2 = p2.next;}return p1;}}return null;}
}

三、力扣160. 相交链表

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode(int x) {*         val = x;*         next = null;*     }* }*/
public class Solution {public ListNode getIntersectionNode(ListNode headA, ListNode headB) {ListNode p1 = headA, p2 = headB;int len1 = 0, len2 = 0;while(p1 != null){len1 ++;p1 = p1.next;}while(p2 != null){len2 ++;p2 = p2.next;}ListNode fast, slow;int edge = 0;if(len1 > len2){edge = len1 - len2;fast = headA;slow = headB;}else{edge = len2 - len1;fast = headB;slow = headA;}while(edge > 0){edge --;fast = fast.next;}while(fast != null && slow != null){if(fast == slow){return fast;}fast = fast.next;slow = slow.next;}return null;}
}

双指针

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode(int x) {*         val = x;*         next = null;*     }* }*/
public class Solution {public ListNode getIntersectionNode(ListNode headA, ListNode headB) {ListNode p1 = headA, p2 = headB;while(p1 != p2){if(p1 == null) p1 = headB;else p1 = p1.next;if(p2 == null) p2 = headA;else p2 = p2.next;}return p1;}
}

四、力扣141. 环形链表

/*** Definition for singly-linked list.* class ListNode {*     int val;*     ListNode next;*     ListNode(int x) {*         val = x;*         next = null;*     }* }*/
public class Solution {public boolean hasCycle(ListNode head) {ListNode p1 = head, p2 = head;while(p1 != null && p2 != null  && p2.next != null){p1 = p1.next;p2 = p2.next.next;if(p1 == p2){return true;}}return false;}
}

相关文章:

力扣labuladong——一刷day02

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、力扣876. 链表的中间结点二、力扣142. 环形链表 II三、力扣160. 相交链表四、力扣141. 环形链表 前言 一、力扣876. 链表的中间结点 /*** Definition for …...

【小白专用23.10.22 已验证】windows 11 安装PHP8.2 +Apache2.4

环境说明 windows:windows 11 x64apache: Apache/2.4.43php :php-8.2.11 一.php 1、PHP下载 PHP For Windows: Binaries and sources Releases 注意&#xff1a; 1.要下载Thread Safe&#xff0c;否则没有php8apache2_4.dll这个文件&#xff1b;如果使用Apache作为服务器…...

Nmap端口服务 之 CentOS7 关于启动Apache(httpd)服务、telnet服务、smtp服务、ftp服务、sftp服务

Nmap端口服务 之 CentOS7 关于启动Apache(httpd)服务、telnet服务、smtp服务、ftp服务、sftp服务 一. CentOS7 安装配置SFTP服务器详解一、SFTP简介二、关闭防火墙三、安装SSH服务在CentOS7中,sftp只是ssh的一部分,所以采用yum来安装ssh服务即可1. 查看是否已经安装了ssh2.…...

为什么 glBegin 未被定义 未定义的标识符,使用新的 API(LearnOpenGL P2)

文章目录 弃用的 glBegin & glEnd使用新 API 的示例 弃用的 glBegin & glEnd 环境&#xff1a;glfw 3.3.8 glad core OpenGL 初学者在尝试使用 glBegin 和 glEnd 函数来绘制三角形时&#xff0c;有可能找到使用这些函数的文章、代码文献 但许多这些函数已经在OpenG…...

C++多态、虚函数、纯虚函数、抽象类

多态的概念 通俗来说&#xff0c;就是多种形态&#xff0c;具体点就是去完成某个行为&#xff0c;当不同的对象去完成时会产生出不同的状态。 举个简单的例子&#xff1a;抢红包&#xff0c;我们每个人都只需要点击一下红包&#xff0c;就会抢到金额。有些人能…...

20231019_vue学习

引入vue.js: <script src"https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script> vue.js <script src"https://cdn.staticfile.org/vue-router/2.7.0/vue-router.min.js"></script> 路由vue模板语法 v-html:添加html模板…...

熟练使用 Redis 的五大数据结构:Java 实战教程

入门 入门阶段主要记住 Redis 的命令&#xff0c;熟练使用 Redis 的 5 大数据结构就可以了。 如果没有 Redis 环境&#xff0c;可以直接通过这个网址https://try.redis.io/&#xff0c;很赞&#xff0c;它会给你模拟一个在线的环境可供你尽情使用&#xff01; 熟练使用Redis的…...

【Linux】kill 命令使用

经常用kill -9 XXX 。一直在kill&#xff0c;除了kill -9 -15 &#xff0c;还能做什么&#xff1f;今天咱们一起学习一下。 kill 命令用于删除执行中的程序或工作。 kill命令 -Linux手册页 命令选项及作用 执行令 man kill 执行命令结果 参数 -l 信号&#xff0c;若果…...

面试-Redis-缓存雪崩

问&#xff1a;什么是缓存雪崩 ? 答&#xff1a;缓存过期是指设置缓存时都采用了同一过期时间&#xff0c;导致缓存在莫一时刻同时失效&#xff0c;从而请求全部全部打到数据库中&#xff0c;导致数据库压力过大而挂机。 它与缓存击穿的区别是&#xff1a;缓存击穿是一个key…...

AI全栈大模型工程师(九)Function Calling 的机制

文章目录 Function Calling 的机制Function Calling 示例 1:加法计算器Function Calling 实例 2:四则混合运算计算器后记Function Calling 的机制 Function Calling 示例 1:加法计算器 需求:用户输入任意可以用加法解决的问题,都能得到计算结果。 # 加载环境变量import o…...

音乐制作软件 Ableton Live 11 Suite mac中文版功能介绍

Ableton Live 11 Suite mac是一款专业级别的音乐制作软件&#xff0c;它提供了多种音乐制作和编辑功能&#xff0c;可以帮助用户创建各种音乐作品。界面简单直观&#xff0c;可以方便地进行各种音乐制作操作。它提供了丰富的音乐制作工具和功能&#xff0c;如录音、采样、编曲、…...

v-model和.sync区别

在vue2中提供了.sync修饰符&#xff0c;但是在vue3中不再支持.sync&#xff0c;取而代之的是v-model。 1.在vue2中v-model和.sync区别&#xff1a; 1.相同点&#xff1a;都是语法糖&#xff0c;都可以实现父子组件中的数据的双向通信。 ​ 区别在于往回传值的时候. sync 的 $…...

django cloudflare csrf 403

网站套了cloudflare flare发现登录接口403了&#xff0c;csrf验证失败&#xff0c; debug设置为False 详细报错如下&#xff1a; Reason given for failure: Referer checking failed - https://xxx/login does not match any trusted origins.In general, this can occur w…...

Hive 中级练习题(40题 待更新)

前言 最近快一周没更了&#xff0c;主要原因是最近在忙另一件事情&#xff08;关于JavaFX桌面软件开发&#xff09;&#xff0c;眼看大三上一半时间就要过去了&#xff0c;抓紧先学Hive&#xff0c;完了把 Spark 剩下的补了&#xff0c;还有 Kafka、Flume&#xff0c;任务还是…...

核酸检测人员安排

题目描述: 在系统、网络均正常的情况下组织核酸采样员和志愿者对人群进行核酸检测筛查。每名采样员的效率不同,采样效率为N人/小时。由于外界变化,采样员的效率会以M人/小时为粒度发生变化,M为采样效率浮动粒度,M=N10%,输入保证N10%的结果为整数。采样员效率浮动规则:采…...

Vue组件间传值

一、父传子 子组件中定义一个props&#xff0c;用来取出父组件传来的值 <script>export default {props:[msg] //子组件定义props} </script> 在父组件中对子组件的自定义属性绑定父组件的变量 <template><div class"parent">//子组件&a…...

《低代码指南》——维格云和Airtable的比较

Airtable​ 什么是Airtable​ Airtable 是一个任务管理应用程序,它合并了电子表格、数据存储和模板,以帮助组织构建他们的工作流程。 适用于哪些企业/组织/人群​ 根据 Airtable 网站,该工具被超过 200,000 个组织的团队使用。 维格表与Airtable相比如何​ Airtable作为…...

牛客:NC59 矩阵的最小路径和

牛客&#xff1a;NC59 矩阵的最小路径和 文章目录 牛客&#xff1a;NC59 矩阵的最小路径和题目描述题解思路题解代码 题目描述 题解思路 动态规划&#xff0c;递推公式&#xff1a;matrix[i][j] min(matrix[i-1][j], matrix[i][j-1]) 题解代码 func minPathSum( matrix [][…...

20231017定时任务

1. 构建定时任务 表达式生成 在线Cron表达式生成器 1.1 启动类 1.2 测试范例 描述: 1,将该类用Component描述,交给spring管理. 2,定时任务方法用Scheduled&#xff0b;cron表达式描述 2. 定时任务的弊端和优化方案 1.假如有一个定时任务,每小时检查关闭超时未支付订单,当10…...

通讯录和内存动态管理

目录 (通讯录)动态增长版 实现效果 找单身狗 题目 源码 思路 三个内存函数的模拟实现 模拟实现strncpy 模拟实现strncat 模拟实现atoi (通讯录)动态增长版 该版本通讯录在原版的基础上增加了检查容量函数&#xff0c;实现了通讯录的动态…...

eNSP-Cloud(实现本地电脑与eNSP内设备之间通信)

说明&#xff1a; 想象一下&#xff0c;你正在用eNSP搭建一个虚拟的网络世界&#xff0c;里面有虚拟的路由器、交换机、电脑&#xff08;PC&#xff09;等等。这些设备都在你的电脑里面“运行”&#xff0c;它们之间可以互相通信&#xff0c;就像一个封闭的小王国。 但是&#…...

多模态2025:技术路线“神仙打架”,视频生成冲上云霄

文&#xff5c;魏琳华 编&#xff5c;王一粟 一场大会&#xff0c;聚集了中国多模态大模型的“半壁江山”。 智源大会2025为期两天的论坛中&#xff0c;汇集了学界、创业公司和大厂等三方的热门选手&#xff0c;关于多模态的集中讨论达到了前所未有的热度。其中&#xff0c;…...

微软PowerBI考试 PL300-选择 Power BI 模型框架【附练习数据】

微软PowerBI考试 PL300-选择 Power BI 模型框架 20 多年来&#xff0c;Microsoft 持续对企业商业智能 (BI) 进行大量投资。 Azure Analysis Services (AAS) 和 SQL Server Analysis Services (SSAS) 基于无数企业使用的成熟的 BI 数据建模技术。 同样的技术也是 Power BI 数据…...

centos 7 部署awstats 网站访问检测

一、基础环境准备&#xff08;两种安装方式都要做&#xff09; bash # 安装必要依赖 yum install -y httpd perl mod_perl perl-Time-HiRes perl-DateTime systemctl enable httpd # 设置 Apache 开机自启 systemctl start httpd # 启动 Apache二、安装 AWStats&#xff0…...

《Playwright:微软的自动化测试工具详解》

Playwright 简介:声明内容来自网络&#xff0c;将内容拼接整理出来的文档 Playwright 是微软开发的自动化测试工具&#xff0c;支持 Chrome、Firefox、Safari 等主流浏览器&#xff0c;提供多语言 API&#xff08;Python、JavaScript、Java、.NET&#xff09;。它的特点包括&a…...

从深圳崛起的“机器之眼”:赴港乐动机器人的万亿赛道赶考路

进入2025年以来&#xff0c;尽管围绕人形机器人、具身智能等机器人赛道的质疑声不断&#xff0c;但全球市场热度依然高涨&#xff0c;入局者持续增加。 以国内市场为例&#xff0c;天眼查专业版数据显示&#xff0c;截至5月底&#xff0c;我国现存在业、存续状态的机器人相关企…...

定时器任务——若依源码分析

分析util包下面的工具类schedule utils&#xff1a; ScheduleUtils 是若依中用于与 Quartz 框架交互的工具类&#xff0c;封装了定时任务的 创建、更新、暂停、删除等核心逻辑。 createScheduleJob createScheduleJob 用于将任务注册到 Quartz&#xff0c;先构建任务的 JobD…...

Qwen3-Embedding-0.6B深度解析:多语言语义检索的轻量级利器

第一章 引言&#xff1a;语义表示的新时代挑战与Qwen3的破局之路 1.1 文本嵌入的核心价值与技术演进 在人工智能领域&#xff0c;文本嵌入技术如同连接自然语言与机器理解的“神经突触”——它将人类语言转化为计算机可计算的语义向量&#xff0c;支撑着搜索引擎、推荐系统、…...

P3 QT项目----记事本(3.8)

3.8 记事本项目总结 项目源码 1.main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); } 2.widget.cpp #include "widget.h" #include &q…...

【2025年】解决Burpsuite抓不到https包的问题

环境&#xff1a;windows11 burpsuite:2025.5 在抓取https网站时&#xff0c;burpsuite抓取不到https数据包&#xff0c;只显示&#xff1a; 解决该问题只需如下三个步骤&#xff1a; 1、浏览器中访问 http://burp 2、下载 CA certificate 证书 3、在设置--隐私与安全--…...