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

网站备案怎么备案杭州网站建设 seo

网站备案怎么备案,杭州网站建设 seo,做网站怎么收费,制定商务网站建设时目录 一、合并两个有序链表 二、两数相加 一、合并两个有序链表 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例 1: 输入:l1 [1,2,4], l2 [1,3,4] 输出:[1,1,2,3,4,4] 示例 2&…

目录

一、合并两个有序链表

二、两数相加



一、合并两个有序链表

将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。

示例 1

 输入:l1 = [1,2,4], l2 = [1,3,4]

输出:[1,1,2,3,4,4]

示例 2

输入:l1 = [], l2 = []

输出:[]

示例 3

输入:l1 = [], l2 = [0]

输出:[0]

提示

  • 两个链表的节点数目范围是 [0, 50]

  • -100 <= Node.val <= 100

  • l1l2 均按 非递减顺序 排列

代码实现一(不设置哨兵位的头结点)

struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2)
{if (list1 == NULL)return list2;else if (list2 == NULL)return list1;
​struct ListNode* newhead = NULL;struct ListNode* tail = NULL;struct ListNode* cur1 = list1;struct ListNode* cur2 = list2;while (cur1 && cur2){if (cur1->val < cur2->val){if (newhead == NULL){newhead = tail = cur1;}else{tail->next = cur1;tail = cur1;}cur1 = cur1->next;}else{if (newhead == NULL){newhead = tail = cur2;}else{tail->next = cur2;tail = cur2;}cur2 = cur2->next;}}if (cur1){tail->next = cur1;}if (cur2){tail->next = cur2;}return newhead;
}

代码实现二(设置哨兵位的头结点)

struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2)
{struct ListNode* guard = (struct ListNode*)malloc(sizeof(struct ListNode));guard->next = NULL;struct ListNode* tail = guard;struct ListNode* cur1 = list1;struct ListNode* cur2 = list2;while (cur1 && cur2){if (cur1->val < cur2->val){tail->next = cur1;tail = cur1;cur1 = cur1->next;}else{tail->next = cur2;tail = cur2;cur2 = cur2->next;}}if (cur1){tail->next = cur1;}if (cur2){tail->next = cur2;}struct ListNode* head = guard->next;free(guard);return head; 
}


二、两数相加

给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。

请你将两个数相加,并以相同形式返回一个表示和的链表。

你可以假设除了数字 0 之外,这两个数都不会以 0 开头。

示例 1

输入:l1 = [2,4,3], l2 = [5,6,4]

输出:[7,0,8]

解释:342 + 465 = 807. 

示例 2

输入:l1 = [0], l2 = [0]

输出:[0]

示例 3

输入:l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]

输出:[8,9,9,9,0,0,0,1]

提示

  • 每个链表中的节点数在范围 [1, 100]

  • 0 <= Node.val <= 9

  • 题目数据保证列表表示的数字不含前导零

代码实现

struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2)
{struct ListNode* guard = (struct ListNode*)malloc(sizeof(struct ListNode));guard->next = NULL;struct ListNode* tail = guard;// 两数相加int sum = 0;while (l1 || l2 || sum){if (l1 != NULL){sum += l1->val;l1 = l1->next;}if (l2 != NULL){sum += l2->val;l2 = l2->next;}// 生成一个新结点struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));newnode->val = sum % 10;  // newnode->val 设置为 sum 的个位newnode->next = NULL;// 尾插tail->next = newnode;tail = newnode;  // 或者写成 tail = tail->next;// 更新 sumsum /= 10;  // sum 更新为原来 sum 的十位}struct ListNode* head = guard->next;free(guard);return head;
}
http://www.hkea.cn/news/487623/

相关文章:

  • 做网站需要多少兆空间wix网站制作
  • 哪些网站教做生物实验今日新闻联播
  • 铜川市住房和城乡建设局网站信息流广告哪个平台好
  • 太原市建设交易中心网站首页百度手机助手app安卓版官方下载
  • 昆山网站建设网站建设郑州网络推广哪个好
  • 瑜伽网站设计国外推广网站
  • 什么网站做国外批发百度推广自己怎么做
  • 网站管理工具百度推广可以自己开户吗
  • 三水网站制作中山做网站推广公司
  • ysl网站设计论文郑州seo地址
  • 做食品的网站设计要注意片多多可以免费看电视剧吗
  • 网站排名推广自己怎么做长沙seo代理商
  • 手机网站改版公司加盟关键词优化排名查询
  • html5 图片网站建设企业网站多少钱
  • 企业网站定制开发流程网络营销的概念及特点
  • 做火影网站背景图农村电商平台有哪些
  • 国内html5网站建设seo兼职工资一般多少
  • 青海西宁网站建设公司百度网络推广
  • 服装公司网站设计百度站长收录入口
  • 做搜索关键词任务网站网站维护是什么意思
  • 2018什么做网站百度网盘网页版入口
  • 深圳福田大型商城网站建设石家庄最新疫情最新消息
  • 网站版面结构chatgpt 网站
  • 网站后期推广是谁来做广州百度推广开户
  • 不上此网站枉做男人免费制作网站平台
  • 防红短链接生成佛山抖音seo
  • 网站建设php带数据库模板站长工具四叶草
  • 做网站客户拖着不验收店铺推广渠道有哪些方式
  • 站群系统哪个好用怎样进行seo推广
  • 淄博网站建设方案网络推广是做什么的