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

南昌网站建设风格企装网

南昌网站建设风格,企装网,站长工具seo域名解析不了,网站前台功能模块介绍常用技巧: 1、画图 2、引入虚拟的头节点 3、不要害怕浪费空间,要勇于定义变量,eg:当链表的插入和删除的时候,为了便于结构体指针的连续性,就需要定义一个新的结构体指针,能更加方便; 4、使用快慢…

常用技巧:

1、画图

2、引入虚拟的头节点

3、不要害怕浪费空间,要勇于定义变量,eg:当链表的插入和删除的时候,为了便于结构体指针的连续性,就需要定义一个新的结构体指针,能更加方便;

4、使用快慢双指针(适用于,判环,找环的入口,找环中倒数第n个节点)。

常用操作:

1、创建一个新节点;

2、尾插;

3、头插。

 第一题:

题解代码:

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/
class Solution {
public:ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {// 新建一个头节点ListNode* newHead = new ListNode(0);ListNode* rail = newHead; // 尾节点// 建立两个工作节点ListNode* cur1 = l1;ListNode* cur2 = l2;int res = 0;while (cur1 || cur2 || res) {if (cur1) {res += cur1->val;cur1 = cur1->next;}if (cur2) {res += cur2->val;cur2 = cur2->next;}ListNode* newNode = new ListNode(res % 10);res = res / 10;rail->next = newNode;rail = rail->next;}ListNode* ret = newHead->next;delete newHead;return ret;}
};

第二题:

题解代码:

 循环➕迭代

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/
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;ListNode* cur = prev->next;ListNode* next = cur->next;ListNode* 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;}//注意这里不能返回head这个节点,因为head这个节点的在整个链表中的相对位置已经改变//应该返回ewhead的->next节点return newHead->next;}
};

第三题:

题解代码: 

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/
class Solution {
public:void reorderList(ListNode* head) {// 处理边界的情况(只有0,1,2,个时就应该返回)if (head == nullptr || head->next == nullptr ||head->next->next == nullptr)return;// 快慢双指针找中间节点ListNode* fast = head;ListNode* slow = head;while (fast && fast->next) {slow = slow->next;fast = fast->next->next;}// 将slow后面的分开并用头插法逆序ListNode* head2 = new ListNode(0);ListNode* cur = slow->next; // 工作指针slow->next = nullptr;while (cur) {// 先将cur的下一个节点存起来ListNode* tail = cur->next;cur->next = head2->next;head2->next = cur;cur = tail;}// 链接两个链表;(双指针)ListNode* cur1 = head;ListNode* cur2 = head2->next;// 定义最终的返回的节点ListNode* ret = new ListNode(0);ListNode* last = ret;while (cur1) {// 先放第一个链表的;last->next = cur1;cur1 = cur1->next;last = last->next;// 再放第二个链表的if (cur2) {last->next = cur2;cur2 = cur2->next;last = last->next;}}delete head2;delete ret;}
};


文章转载自:

http://NJUgkcgD.cjmmt.cn
http://MFBROjhC.cjmmt.cn
http://f1uV6HoI.cjmmt.cn
http://l50r1Cbo.cjmmt.cn
http://7rMNEtME.cjmmt.cn
http://TRAgYDhd.cjmmt.cn
http://C26aBGp2.cjmmt.cn
http://XHoI4Ey4.cjmmt.cn
http://KzglqeDN.cjmmt.cn
http://6uRxBj17.cjmmt.cn
http://lfylViS2.cjmmt.cn
http://rQCQQWsk.cjmmt.cn
http://PnARtaMX.cjmmt.cn
http://5plBpl3P.cjmmt.cn
http://gmgnKz1R.cjmmt.cn
http://1osiK3Oo.cjmmt.cn
http://scEbjDsF.cjmmt.cn
http://qx4W5HHm.cjmmt.cn
http://QAJJEFRx.cjmmt.cn
http://H0y8fA2l.cjmmt.cn
http://xRuw1djk.cjmmt.cn
http://BIRdhhJQ.cjmmt.cn
http://3UCpdE2o.cjmmt.cn
http://w4qCCQ3Q.cjmmt.cn
http://ezYCO9p6.cjmmt.cn
http://SuzH3kjm.cjmmt.cn
http://oh3tLNzx.cjmmt.cn
http://xFA3IbC4.cjmmt.cn
http://n3oh16WF.cjmmt.cn
http://kKMVjFKN.cjmmt.cn
http://www.dtcms.com/wzjs/671960.html

相关文章:

  • 服务器 网站建设 过程信仰类型的企业网站
  • 修改网站主目录的位置专业企业网站建设价格
  • 容桂手机网站建设长沙有哪些正规传媒公司
  • 织梦网站密码忘记做视频网站 带宽
  • 郑州有学网站制作没有备案的网站怎么访问
  • 宜昌 网站建设邯郸市最新招聘信息
  • 网站开发要学网站建设方案申请
  • 广州网站百度排名推广wordpress插件丢失
  • 保山市建设厅网站什么关键词可以搜到那种
  • 网站设计时图片怎么做高质量视频素材网站
  • 怎么做一个免费的网站网站建设与管理 教学视频
  • 如何建设互联网政务门户网站网站的建设时间
  • 汕头企业网站建站模板joomla做类似赶集网的网站
  • 龙口建网站公司价格男孩做网站
  • 阳逻开发区网站建设中企动力不符合网站外链建设原则的是
  • 网站推广 2015谷歌游戏网页制作代码
  • 人工智能在线ai写作网站最新网页游戏传奇
  • 外网进入学校内局域网建设的网站做外贸网站机构
  • 网站开发所需要的的环境页制作与网站建设技术大全
  • 精选合肥网站建设家具网站建设策划方案
  • 360网站提交wordpress评论不要地址邮箱
  • 游戏网站域名网站编程语言培训机构
  • 建站公司用wordpress网站推广员需要做什么
  • 5118站长工具快速排名推荐
  • 互联网站外推广免费落地页制作平台
  • 杭州高端网站建设公司哪家好帮客户做网站平台犯法吗
  • 一个ip可以建设多少个网站深圳系统网站开发
  • 做网站域名wordpress使用国外主题
  • 最全的数据网站网站的关键词库怎么做的那么多
  • 网站制作素材龙华网站建设多少钱