博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode 21 Merge Two Sorted Lists
阅读量:4185 次
发布时间:2019-05-26

本文共 920 字,大约阅读时间需要 3 分钟。

// Author : yqtao// Date   : 2016-7-3// Email  : yqtao@whu.edu.cn/************************************************************************************ Merge two sorted linked lists and return it as a new list.The new list should be* made by splicing together the nodes of the first two lists.*********************************************************************************** //*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode(int x) : val(x), next(NULL) {}* };*/ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {    ListNode dummy(INT_MIN);    ListNode *tail = &dummy;    while (l1 && l2) {
if (l1->val < l2->val) {
tail->next = l1; l1 = l1->next; } else {
tail->next = l2; l2 = l2->next; } tail = tail->next; } tail->next = l1 ? l1 : l2; return dummy.next;}

转载地址:http://dpdoi.baihongyu.com/

你可能感兴趣的文章
Number of 1s
查看>>
CareerCup Find all the conflicting appointments from a given list of n appointments.
查看>>
CareerCup Given an array having positive integers, find a subarray which adds to a given number
查看>>
CareerCup Generate all the possible substrings
查看>>
CareerCup Given an array A[], find (i, j) such that A[i] < A[j] and (j - i) is maximum.
查看>>
Brain Teaser 球变色
查看>>
(2)考试大纲---信息系统项目管理师考试系列
查看>>
(3)教材目录---信息系统项目管理师考试系列
查看>>
商城基础E-R模型图
查看>>
飞翔的小鸟--键盘事件案例
查看>>
一个sql函数group_concat详解
查看>>
根据地址返回坐标位置的百度地图api
查看>>
thinkcmf数据字典
查看>>
gitflow 分支原理
查看>>
4字节 整数哈希 ----------jenkins 32位Hash算法
查看>>
哈希函数的逆向算法
查看>>
1-3 beanstalkd参数
查看>>
git版本控制管理系列-----第四章 GIT基本概念
查看>>
mysql 库级权限、表级权限授权
查看>>
TensorFlow中的单层神经网络
查看>>