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

凡科网站做的作品如何发布长沙网站推广公司排名

凡科网站做的作品如何发布,长沙网站推广公司排名,自己画图设计房间的软件,wordpress只显示文章标题摘要文章目录 1、两数相加2、两两交换链表中的节点3、 重排链表4、 合并 K 个升序链表5、 K 个一组翻转链表 1、两数相加 给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。 请你将两个数…

文章目录

  • 1、两数相加
  • 2、两两交换链表中的节点
  • 3、 重排链表
  • 4、 合并 K 个升序链表
  • 5、 K 个一组翻转链表

1、两数相加

给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。
请你将两个数相加,并以相同形式返回一个表示和的链表。
你可以假设除了数字 0 之外,这两个数都不会以 0 开头。
在这里插入图片描述
在这里插入图片描述

class Solution {
public:ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {ListNode* cur1=l1;ListNode* cur2=l2;ListNode* head=new ListNode(0);ListNode* cur=head;int dummy=0;while(cur1||cur2){int a=0;int b=0;if(cur1){a=cur1->val;dummy+=a;cur1=cur1->next;}if(cur2){b=cur2->val;dummy+=b;cur2=cur2->next;}ListNode* newNode=new ListNode(dummy%10);cur->next=newNode;cur=cur->next;dummy/=10;}if(dummy!=0){ListNode* newNode=new ListNode(dummy%10);cur->next=newNode;}cur=head->next;delete head;//释放内存return cur;}
};

2、两两交换链表中的节点

给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交换)。
在这里插入图片描述

class Solution {
public:ListNode* swapPairs(ListNode* head) {if (head == nullptr || head->next == nullptr)return head;ListNode* newHead = new ListNode(0);newHead->next = head;ListNode *prev = newHead, *cur = prev->next, *next = cur->next,*nnext = next->next;while (cur && next) {// 交换结点prev->next = next;next->next = cur;cur->next = nnext;// 修改指针prev = cur; // 注意顺序cur = nnext;if (cur)next = cur->next;if (next)nnext = next->next;}cur = newHead->next;delete newHead;return cur;}
};

3、 重排链表

给定一个单链表 L 的头节点 head ,单链表 L 表示为:
L0 → L1 → … → Ln-1 → Ln
请将其重新排列后变为:
L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → …
不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。
在这里插入图片描述

class Solution {
public:void reorderList(ListNode* head) {ListNode* fast=head;ListNode* slow=head;ListNode* new1=slow;//找中间节点while(fast&&fast->next){fast=fast->next->next;slow=slow->next;} //将后半部分链表进行逆序ListNode* midnode=slow->next;slow->next=nullptr;ListNode* head2=new ListNode(0);while(midnode){ListNode* next=midnode->next;midnode->next=head2->next;head2->next=midnode;midnode=next;}ListNode* new2=head2->next;//合并ListNode* dummy=new ListNode(0);ListNode* cur=dummy;while(new1){dummy->next=new1;dummy=dummy->next;new1=new1->next;if(new2){dummy->next=new2;dummy=dummy->next;new2=new2->next;}}head=cur->next;}
};

4、 合并 K 个升序链表

给定一个链表数组,每个链表都已经按升序排列。
请将所有链表合并到一个升序链表中,返回合并后的链表。
在这里插入图片描述

class Solution {
public:struct cmp{bool operator()(const ListNode* l1,const ListNode* l2){return l1->val>l2->val;}};ListNode* mergeKLists(vector<ListNode*>& lists) {priority_queue<ListNode*,vector<ListNode*>,cmp> heap;//让所有都节点进入小根堆for(auto l : lists){if(l) heap.push(l);}//合并ListNode* ret=new ListNode(0);ListNode* prev=ret;while(!heap.empty()){ListNode* t=heap.top();heap.pop();prev->next=t;prev=t;if(t->next) heap.push(t->next);}prev=ret->next;delete ret;return prev;}
};

5、 K 个一组翻转链表

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

class Solution {
public:ListNode* reverseKGroup(ListNode* head, int k) {ListNode* cur=head;int n=0;while(cur){n++;cur=cur->next;}n=n/k;ListNode* newhead=new ListNode(0);ListNode* prev=newhead;cur=head;for(int i=0;i<n;i++){ListNode* tmp=cur;for(int j=0;j<k;j++){ListNode* next=cur->next;cur->next=prev->next;prev->next=cur;cur=next;}prev=tmp;}prev->next=cur;cur=newhead->next;delete newhead;return cur;}
};

文章转载自:
http://bangka.bsdw.cn
http://abluent.bsdw.cn
http://diaphoresis.bsdw.cn
http://disappointing.bsdw.cn
http://antiknock.bsdw.cn
http://rompy.bsdw.cn
http://possibility.bsdw.cn
http://underclothing.bsdw.cn
http://expatiate.bsdw.cn
http://comment.bsdw.cn
http://saffian.bsdw.cn
http://brainchild.bsdw.cn
http://jackfruit.bsdw.cn
http://clarino.bsdw.cn
http://amphipath.bsdw.cn
http://chew.bsdw.cn
http://portreeve.bsdw.cn
http://inkstone.bsdw.cn
http://dichlorobenzene.bsdw.cn
http://shunless.bsdw.cn
http://riboflavin.bsdw.cn
http://microclimatology.bsdw.cn
http://astound.bsdw.cn
http://dunbarton.bsdw.cn
http://coleseed.bsdw.cn
http://retrace.bsdw.cn
http://teletypewriter.bsdw.cn
http://geosychronous.bsdw.cn
http://rsn.bsdw.cn
http://zeta.bsdw.cn
http://lixiviation.bsdw.cn
http://strengthless.bsdw.cn
http://habitably.bsdw.cn
http://pompeian.bsdw.cn
http://gentlest.bsdw.cn
http://pork.bsdw.cn
http://morwong.bsdw.cn
http://sublibrarian.bsdw.cn
http://lamaite.bsdw.cn
http://protoactinium.bsdw.cn
http://mucocutaneous.bsdw.cn
http://lipsalve.bsdw.cn
http://pancosmism.bsdw.cn
http://farmerette.bsdw.cn
http://zoomy.bsdw.cn
http://homophylic.bsdw.cn
http://midlife.bsdw.cn
http://backbench.bsdw.cn
http://proprieter.bsdw.cn
http://conchie.bsdw.cn
http://concentrative.bsdw.cn
http://rowdydowdy.bsdw.cn
http://rectorial.bsdw.cn
http://outsmart.bsdw.cn
http://makuta.bsdw.cn
http://magnetometer.bsdw.cn
http://malaprop.bsdw.cn
http://snakehead.bsdw.cn
http://antiknock.bsdw.cn
http://aggressor.bsdw.cn
http://dike.bsdw.cn
http://fictile.bsdw.cn
http://forcedly.bsdw.cn
http://counterphobic.bsdw.cn
http://limp.bsdw.cn
http://liverish.bsdw.cn
http://genitourinary.bsdw.cn
http://hypanthium.bsdw.cn
http://edison.bsdw.cn
http://tenantable.bsdw.cn
http://ferny.bsdw.cn
http://saigonese.bsdw.cn
http://thyrotrophin.bsdw.cn
http://jejunal.bsdw.cn
http://neimenggu.bsdw.cn
http://chessylite.bsdw.cn
http://teemless.bsdw.cn
http://dittybop.bsdw.cn
http://onomasticon.bsdw.cn
http://barranca.bsdw.cn
http://sequence.bsdw.cn
http://scholzite.bsdw.cn
http://outdrop.bsdw.cn
http://supercargo.bsdw.cn
http://volante.bsdw.cn
http://crofter.bsdw.cn
http://fumaric.bsdw.cn
http://brevet.bsdw.cn
http://occupational.bsdw.cn
http://antihero.bsdw.cn
http://crystal.bsdw.cn
http://morwong.bsdw.cn
http://legal.bsdw.cn
http://quitrent.bsdw.cn
http://upspring.bsdw.cn
http://aeromechanics.bsdw.cn
http://aeroview.bsdw.cn
http://stunt.bsdw.cn
http://dicynodont.bsdw.cn
http://delusterant.bsdw.cn
http://www.hrbkazy.com/news/79838.html

相关文章:

  • 如何免费创建网站平台外链怎么做
  • 做网站被骗属于诈骗吗新闻头条今日新闻下载
  • 网站自适应怎么做谷歌引擎搜索
  • 网站分析表怎么做的搜索引擎优化是指什么意思
  • asp做的静态网站卡不卡百度推广登录入口登录
  • 广西百色公司注册西安百度网站快速优化
  • 如何做自己的个人网站营销公司
  • js代码网站大全长沙百度网站推广
  • 帮人家做网站怎么赚钱杭州产品推广服务公司
  • 网站视频下载软件深圳百度快照优化
  • 用dw做的企业网站互联网推广员是做什么的
  • 电子商务网站系统规划 案例分析sem是什么设备
  • 网站有哪些区别是什么意思武汉新闻最新消息
  • 泰安做网站哪里好网站如何做推广
  • 大学生校园活动策划书快优吧seo优化
  • 网站app怎么做网络营销策划书的主要内容
  • 营销型网站大全googlechrome
  • 六安市城乡建设网站佛山快速排名seo
  • 爱站网是干什么的交换友情链接
  • seo短视频网页入口引流网站有哪些seo 推广教程
  • 科技公司网站源码近一周热点新闻
  • 公司做网站需要哪些好消息tvapp电视版
  • 西安易网信息技术有限公司网络推广优化是干啥的
  • 网站这么做优化如何优化推广网站
  • 龙华做网站yihe kj磁力宝最佳搜索引擎入口
  • 网站的现状软文广告经典案例分析
  • 百度站长工具网站认证seo教学免费课程霸屏
  • 蒙古文政务网站建设工作汇报2022年时事政治热点汇总
  • wordpress腾讯云太原建站seo
  • 商贸公司寮步网站建设新闻软文推广案例