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

个人网站怎么做支付功能关键词优化公司排名

个人网站怎么做支付功能,关键词优化公司排名,网站快照怎么做,saas建站平台源码文章目录 一、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.wangmingla.cn/news/159964.html

相关文章:

  • 用wordpress付费网站大数据分析
  • 做网站一年多少钱网络营销的特征和功能
  • 织梦网站如何做移动端网页制作网站
  • 学做网站好学吗2021年搜索引擎排名
  • 招聘门户网站有哪些南宁网络优化seo费用
  • 全局右下角弹窗wordpressseo与sem的关系
  • 番禺网站公司淘宝店铺怎么引流推广
  • 网页设计茶叶网站建设安徽搜索引擎优化seo
  • 免费网站后台管理系统模板乔拓云智能建站平台
  • 北京网站建设 都选万维科技重庆seo职位
  • wordpress中的联系方式seo查询爱站
  • 网站建设费用表网络app推广是什么工作
  • 网站后台管理系统用什么软件做线上营销策略都有哪些
  • 只做正品的购物网站网站优化排名软件
  • 德宏芒市建设局网站外链图片
  • 如何做攻击类型网站网站推广和宣传的方法
  • 珠海网站建立福州网站建设策划
  • 网站不想备案宠物美容师宠物美容培训学校
  • 做养生网站需要资质吗跨境电商平台推广
  • 网站提示域名解析错误怎么办5118网站查询
  • 资源分享类网站模板北京网站优化排名推广
  • 温州专业微网站制作做网站
  • 小网站asp好还是php好网络销售怎么做
  • 汝南专业网站建设网络营销工具分析
  • 各类网站建设软文营销的技巧有哪些?
  • 铁路网站建设论文百度怎么做广告
  • 三项措施做好门户网站建设中山谷歌推广
  • 网站用词精准性软文发布平台与板块
  • 常州做网站需要多少钱今日新闻50字
  • 安徽网页设计厦门seo俱乐部