• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






Sunshineboy1

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

2020年7月16日

leetcode-206-Reverse Linked List
摘要: 思路: 1->2->3->4->5 要实现翻转 1、让a=head,b=head->next, 2、翻转 auto c=b->next b->next=a a=b b=c 3.直到head->next=null 4.返回a 代码: /** * Definition for singly-linked 阅读全文
posted @ 2020-07-16 16:34 Sunshineboy1 阅读(70) 评论(0) 推荐(0)
 
leetcode-24-Swap Nodes in Pairs
摘要: 思路: 1、由于head 节点可能产生变化,所以创建一个虚拟的头指针 dummy 2.p=dummy,a=p->next,b=p->next->next 3.交换 p->next=b; a->next=b->next; b->next=a; p=a; 代码: /** * Definition for 阅读全文
posted @ 2020-07-16 14:52 Sunshineboy1 阅读(117) 评论(0) 推荐(0)
 
leetcode-61-Remove Nth Node From End of List
摘要: 思路: 先让first指针移动n个节点,只要first->next!=null first&second 同时移动,知道first->next==null 让second->next=second->next->next,就实现删除节点操作 代码: /** * Definition for sing 阅读全文
posted @ 2020-07-16 14:32 Sunshineboy1 阅读(95) 评论(0) 推荐(0)
 
leetcode-61-remove rotate list
摘要: 思路: 双指针法 1、判断链表是否为null 2.获取链表长度--遍历链表 3.向然first指针移动K个位置 4.只要first->next!=null 让second &first指针同时移动,直到first->next==null 5.将链表首尾相连--first->next=head 得到新 阅读全文
posted @ 2020-07-16 14:15 Sunshineboy1 阅读(77) 评论(0) 推荐(0)
 
leetcode-82-remove duplicates from sorted list
摘要: 思路: 1、将链表中head指针移动进行元素的删除,总共有两种情况 a.head->next->val==head->val 直接将head->next 移动到head->next->next 查找出所有相同的元素的区段 b.head->next->val !=head->val 将head 移动到 阅读全文
posted @ 2020-07-16 11:21 Sunshineboy1 阅读(87) 评论(0) 推荐(0)