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

软件开发价格标准企业seo培训

软件开发价格标准,企业seo培训,长沙网站快速排名优化,多用户商城网站建设方案文章目录 一、206.反转链表二、92.反转链表 ||三、25. K 个一组翻转链表 一、206.反转链表 class Solution { public://使用头插//三个指针也可以ListNode* reverseList(ListNode* head) {if(headnullptr)return nullptr;ListNode* curhead;ListNode* newheadnew ListNode(0);L…

文章目录

  • 一、206.反转链表
  • 二、92.反转链表 ||
  • 三、25. K 个一组翻转链表

一、206.反转链表

在这里插入图片描述
在这里插入图片描述

class Solution {
public://使用头插//三个指针也可以ListNode* reverseList(ListNode* head) {if(head==nullptr)return nullptr;ListNode* cur=head;ListNode* newhead=new ListNode(0);ListNode* pre=newhead;while(cur){ListNode* next=cur->next;cur->next=pre->next;pre->next=cur;cur=next;}cur=newhead->next;delete newhead;return cur;}
};

二、92.反转链表 ||

给你单链表的头指针 head 和两个整数 left 和 right ,其中 left <= right 。请你反转从位置 left 到位置 right 的链表节点,返回 反转后的链表

在这里插入图片描述

/更简洁
class Solution {
public:ListNode *reverseBetween(ListNode *head, int left, int right) {ListNode *dummy = new ListNode(0, head), *p0 = dummy;for (int i = 0; i < left - 1; ++i)p0 = p0->next;ListNode *pre = nullptr, *cur = p0->next;for (int i = 0; i < right - left + 1; ++i) {ListNode *nxt = cur->next;cur->next = pre; // 每次循环只修改一个 next,pre = cur;cur = nxt;}p0->next->next = cur;p0->next = pre;return dummy->next;}
};// class Solution {
// public://使用头插,使用哨兵节点,left可能为一
//     ListNode* reverseBetween(ListNode* head, int left, int right) {
//         if(left==right)
//         {
//             return head;
//         }
//         int sign=1;
//         ListNode* cur=head;
//         ListNode* newhead=new ListNode(0);
//         ListNode* tmp=newhead;
//         ListNode* firstinsert=nullptr;
//         while(cur)
//         {
//             ListNode* next=cur->next;
//             if(sign==left)
//             {
//                 firstinsert=cur;
//             }
//             if(sign>=left&& sign<=right)
//             {
//                 cur->next=tmp->next;
//                 tmp->next=cur;
//                 cur=next;
//                 if(sign==right)
//                 {
//                     tmp=firstinsert;
//                     if(cur==nullptr)
//                     {
//                         firstinsert->next=nullptr;
//                     }
//                 }
//             }
//             else
//             {
//                 tmp->next=cur;
//                 tmp=cur;
//                 cur=next;  
//             }
//             sign++;
//         }
//         cur=newhead->next;
//         delete newhead;
//         return cur;
//     }
// };

三、25. K 个一组翻转链表

给你链表的头节点 head ,每 k 个节点一组进行翻转,请你返回修改后的链表。
k 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 k 的整数倍,那么请将最后剩余的节点保持原有顺序。
你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。
在这里插入图片描述

class Solution {
public://思路是进行头插ListNode *reverseKGroup(ListNode *head, int k) {//先遍历链表,看需要反转几次int n=0;ListNode* cur=head;while(cur){cur=cur->next;n++;}n=n/k;//这就是要反转几次的结果cur=head;ListNode* newhead=new ListNode(0);ListNode* pre=newhead;for(int i=0;i<n;i++){ListNode* tmp=cur;for(int i=0;i<k;i++){ListNode* next=cur->next;cur->next=pre->next;pre->next=cur;cur=next;}pre=tmp;}//处理不需要反转的pre->next=cur;cur=newhead->next;delete newhead;return cur;}
};
http://www.yidumall.com/news/31406.html

相关文章:

  • 兰州做网站客户毕节地seo
  • 微擎可以做企业网站吗代运营一家店铺多少钱
  • 做的网站没法本地上传图片最新战争新闻事件今天
  • 厦门网站建设是什么意思郑州网站推广优化
  • 个人做淘宝客网站好做吗360搜索建站
  • 如何在网站上做飘窗链接站长工具使用
  • 如何做自己的淘宝优惠券网站百度快速收录网站
  • 做网站分pc端和移动端的吗福州短视频seo公司
  • wordpress网站排行榜seo营销专员
  • 黄村网站开发公司三台网站seo
  • 为什么公司网站打不开全网营销是什么
  • 招聘网站建设保定2345网址导航下载桌面
  • 公司网站运营注意事项宁波seo怎么做引流推广
  • 网络营销型企业网站案例销售技巧和话术
  • 网站设计师需要学什么网站排名在线优化工具
  • 宁波自己建网站外贸营销型网站制作公司
  • 学生为学校做网站百度账号登录入口
  • 做网站用什么字体字号网络游戏推广公司
  • 网站建设咨询哪家性价比高电商营销策略
  • 企业整站网站模板下载百度一下你知道
  • 大学生做企业网站中国搜索引擎市场份额
  • 国内企业网站设计百度大数据查询怎么用
  • WordPress设置用户访问个数江门关键词排名优化
  • 做网站和网站页面设计线上销售渠道有哪几种
  • 大丰微信网站开发公司怎样注册网站免费注册
  • 用阿里云服务器做刷单网站搜索关键词推荐
  • 备案图标怎么放在网站中广州市新闻发布
  • 广东微信网站制作报价表短视频关键词优化
  • 网站建设需求方案网络推广平台有哪些渠道
  • 下载网站后怎么做产品营销