![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
链表
红茶晚报丶
在校大学生,正在勤奋中
展开
-
力扣-->#剑指Offer 206.反转链表
public class Solution { public ListNode detectCycle(ListNode head) { ListNode fast=head; ListNode slow=head; while(fast!=null&&fast.next!=null){ fast=fast.next.next; slow=slow.next; ...原创 2022-03-26 12:38:02 · 203 阅读 · 0 评论 -
力扣-->#剑指Offer 206.反转链表
方法一:双指针(1)定义一个指针cur指向头结点,再定义一个指针pre指向null,然后开始反转(2)在反转之前需要保存cur.next指针,不然就找不到了class Solution { public ListNode reverseList(ListNode head) { if(head==null) return head; ListNode pre=null; ListNode cur=head; List..原创 2022-03-23 15:35:29 · 82 阅读 · 0 评论 -
单链表反转
class Solution { public ListNode reverseList(ListNode head) { ListNode pre=null; ListNode cur=head; while(cur!=null){ ListNode temp=cur.next; cur.next=pre; pre=cur; cur=temp; ...原创 2021-11-09 10:42:36 · 184 阅读 · 0 评论 -
E链表中间
class Solution { public ListNode middleNode(ListNode head) { ListNode slow=head,fast=head; while(fast!=null&&fast.next!=null){ slow=slow.next; fast=fast.next.next; } return slow; ...原创 2021-11-08 15:46:11 · 177 阅读 · 0 评论 -
链表E(合并两个排序列表)
递归:不好之处,如果链表过长,会导致栈内存溢出原创 2021-11-02 19:46:50 · 86 阅读 · 0 评论