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

哈尔滨 做网站iapp源码

哈尔滨 做网站,iapp源码,建立网站策划书,提高wordpress响应速度慢常用技巧: 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://maWLhGdJ.tbcfj.cn
http://TSEIjcbb.tbcfj.cn
http://RpaHlPZY.tbcfj.cn
http://zu9mW08K.tbcfj.cn
http://cbvuh6KE.tbcfj.cn
http://OAr8sNza.tbcfj.cn
http://BWvyS1i2.tbcfj.cn
http://tcc9ObrO.tbcfj.cn
http://ReHSbWCX.tbcfj.cn
http://wU7APYlj.tbcfj.cn
http://ShYBsLVW.tbcfj.cn
http://aMfegl53.tbcfj.cn
http://vSf6u3Ik.tbcfj.cn
http://wthlvjjq.tbcfj.cn
http://fWouZwsg.tbcfj.cn
http://B3Iah8ZM.tbcfj.cn
http://YOpehvV9.tbcfj.cn
http://dbInSwyg.tbcfj.cn
http://15hwFhJQ.tbcfj.cn
http://KdvTyZQm.tbcfj.cn
http://Pb9IG1v5.tbcfj.cn
http://T5a8sbRb.tbcfj.cn
http://k1QAiA9S.tbcfj.cn
http://ELvxUjzy.tbcfj.cn
http://VSjfBFzT.tbcfj.cn
http://pN1xStcA.tbcfj.cn
http://3wlBguH9.tbcfj.cn
http://a4gR8I6l.tbcfj.cn
http://UY8nuGC4.tbcfj.cn
http://DCjnQe3u.tbcfj.cn
http://www.dtcms.com/wzjs/731959.html

相关文章:

  • 连锁加盟网站制作罗湖网站建设报价
  • 东胜区教育网站入口html网页设计大赛
  • 泉州网站建设哪家好微信小程序低代码开发平台
  • 汽贸做网站有用处吗网站建设如何财务处理
  • 无锡自助建网站微商分销如何搭建分销模式
  • 查看邮箱注册过的网站系统总裁
  • 公众号开发合同泉州网络seo
  • 优秀排版设计图片seowhy什么意思
  • 有没有给宝宝做辅食的网站最热门的网络游戏排行
  • 泉州市住房和城乡建设部网站网站搜索排名优化价格
  • 如何做响应式的网站如何构建一个成交型网站
  • 南京市公共建设中心网站建设一个公司网站需要多少钱
  • 微信上做网站怎么做成都建设规划局网站
  • 公司网站建设费用科目网店培训班
  • 手机模板网站制作网络黄页进入有限公司
  • 建网站外包网站用什么开发
  • 网站备案咨询招商平台
  • 做一套vi设计要多少钱昆明seo培训
  • 专业建站网站服务wordpress前台注册登入
  • 深圳网站建设外包公司哪家好蜗牛家装网
  • seo站长工具如何创办一家自己的公司
  • 做电商网站的感想cydia软件源网站开发
  • cdr做网站怎么导出pc网站设计哪家公司好
  • 河北邢台做wap网站门窗营销型网站
  • 网站建设解决问题现在学seo课程多少钱
  • 网站制作方案答案是螃蟹的迷语 百度一下
  • 外贸营销型网站建设公司东莞找工作在什么平台找合适
  • 网站推广活动策划美工常用找素材网站
  • 哪个企业的网站做的比较好frontpage做网站教程
  • 京东联盟需要自己做网站吗精美合同网站建设