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

建设高校网站的现实意义odoo网站建设

建设高校网站的现实意义,odoo网站建设,做酸菜视频网站,旅游网站开发内容题目来源 21. 合并两个有序链表 - 力扣(LeetCode) 题目描述 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例 示例 1: 输入:l1 [1,2,4], l2 [1,3,4] 输出&#xff1…

题目来源

21. 合并两个有序链表 - 力扣(LeetCode)

题目描述

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

示例

示例 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
  • l1 和 l2 均按 非递减顺序 排列

题目解析

本题的要求是:需要使用 list1 和 list2 的节点来构成合并后的链表。

这里我们可以为合并后的链表创建一个虚拟头节点 dummy_head,之后按照下面图示逻辑进行:

C源码实现

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {struct ListNode* dummy_head = (struct ListNode*)malloc(sizeof(struct ListNode));dummy_head->val = 0;dummy_head->next = NULL;struct ListNode* tail = dummy_head;while (list1 != NULL && list2 != NULL) {if (list1->val < list2->val) {tail->next = list1;list1 = list1->next;} else {tail->next = list2;list2 = list2->next;}tail = tail->next;}tail->next = list1 != NULL ? list1 : list2;return dummy_head->next;
}

C++源码实现

/*** 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* mergeTwoLists(ListNode* list1, ListNode* list2) {ListNode* dummy_head = new ListNode(0, nullptr);ListNode* tail = dummy_head;while (list1 != nullptr && list2 != nullptr) {if (list1->val < list2->val) {tail->next = list1;list1 = list1->next;} else {tail->next = list2;list2 = list2->next;}tail = tail->next;}tail->next = list1 != nullptr ? list1 : list2;return dummy_head->next;}
};

Java源码实现

/*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}* ListNode(int val) { this.val = val; }* ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode mergeTwoLists(ListNode list1, ListNode list2) {ListNode dummy_head = new ListNode(0, null);ListNode tail = dummy_head;while (list1 != null && list2 != null) {if (list1.val < list2.val) {tail.next = list1;list1 = list1.next;} else {tail.next = list2;list2 = list2.next;}tail = tail.next;}tail.next = list1 != null ? list1 : list2;return dummy_head.next;}
}

Python源码实现

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution(object):def mergeTwoLists(self, list1, list2):""":type list1: Optional[ListNode]:type list2: Optional[ListNode]:rtype: Optional[ListNode]"""dummy_head = ListNode(0, None)tail = dummy_headwhile list1 != None and list2 != None:if list1.val < list2.val:tail.next = list1list1 = list1.nextelse:tail.next = list2list2 = list2.nexttail = tail.nexttail.next = list1 if list1 else list2return dummy_head.next

JavaScript源码实现

/*** Definition for singly-linked list.* function ListNode(val, next) {*     this.val = (val===undefined ? 0 : val)*     this.next = (next===undefined ? null : next)* }*/
/*** @param {ListNode} list1* @param {ListNode} list2* @return {ListNode}*/
var mergeTwoLists = function (list1, list2) {const dummy_head = new ListNode(0, null);let tail = dummy_head;while (list1 != null && list2 != null) {if (list1.val < list2.val) {tail.next = list1;list1 = list1.next;} else {tail.next = list2;list2 = list2.next;}tail = tail.next;}tail.next = list1 != null ? list1 : list2;return dummy_head.next;
};


文章转载自:

http://1jpnCZwp.bnLkc.cn
http://TDQP7MuX.bnLkc.cn
http://6jIcBgTO.bnLkc.cn
http://DUKokQQo.bnLkc.cn
http://DXTLpqtx.bnLkc.cn
http://cFfWKidq.bnLkc.cn
http://pMKnEpJX.bnLkc.cn
http://5TQZrlde.bnLkc.cn
http://TToJWt4w.bnLkc.cn
http://MVw5TUpD.bnLkc.cn
http://zuPRSI6L.bnLkc.cn
http://hi9rOn08.bnLkc.cn
http://xL73pyCE.bnLkc.cn
http://zu4N7nVL.bnLkc.cn
http://cewos7Ss.bnLkc.cn
http://WW0PixBK.bnLkc.cn
http://ZjWWTjU2.bnLkc.cn
http://IFVVZ6Xo.bnLkc.cn
http://jINhnuPw.bnLkc.cn
http://qFQF8Aud.bnLkc.cn
http://ogbMehPX.bnLkc.cn
http://wqQ3mbMj.bnLkc.cn
http://EOtjjmmJ.bnLkc.cn
http://Kd4EGA5M.bnLkc.cn
http://inV4Q92K.bnLkc.cn
http://aHvXn6jE.bnLkc.cn
http://U71E7Z6K.bnLkc.cn
http://AsTFjKol.bnLkc.cn
http://LjZP5xHB.bnLkc.cn
http://hrqGj05J.bnLkc.cn
http://www.dtcms.com/wzjs/741823.html

相关文章:

  • 阿里巴巴做网站营销有没有用电子商务网站建设与管理总结
  • 企业网站如何建设温州可以做驾校推广的网站
  • 网站开发个人工作室信息网站有哪些
  • 用什么做响应式网站春雨app直播免费看
  • 网站没有权重广州自助公司建网站企业
  • 杭州网站搜索排名网站推广优化如何做
  • 网站首屏高度用fullpage做的网站
  • 鹤壁做网站价格南京网站快速排名提升
  • 局域网内网站建设的步骤过程有没有电商设计的网站参考
  • 教育网站制作实训报告网站优化的方法有哪些
  • 网站模板加后台福州网站排名优化
  • 关于建设网站的报告广东个人备案网站内容
  • 软件开发费和网站建设集团网站设计方案
  • 做SEO用dede还是wordpress游戏优化软件
  • 北京城建设计集团网站外贸网站建设青岛
  • 邢台网站网页设计一等一网站建设
  • 番禺区pc端网站建设兔展在线制作网站
  • 在线教育网站建设方案org后缀的网站
  • 做企业网站需要什么广东新闻频道直播
  • 甘肃住房城乡建设厅网站首页wordpress退出
  • 广东省高校质量工程建设网站同心食品厂网站建设项目任务分解
  • 网站开发运营公司系统里看不到wordpress
  • 怎么查寻一个网站做的竞价免费网站设计定制
  • 衡水网站制作设计网络推广的几种主要方法
  • 设计接单子网站做排行榜的网站
  • 网站做管制户外刀具网站后台上传内容前台首页不显示
  • 淄博什么兼职的网站建设锚文本外链网站
  • 网站建立多少钱网站开发团队人员
  • 淘宝做的网站会不会过期有一个做场景动画的网站
  • 开放一个网站多少钱网站建设路由器怎么设置