当前位置:网站首页>Leetcode sword finger offer jz25 merges two sorted linked lists
Leetcode sword finger offer jz25 merges two sorted linked lists
2022-07-24 06:25:00 【Happy and at ease】

It is known that the two linked lists to be merged are incremental permutations , When merging into a new linked list, we can consider creating a pseudo header
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*
* C Language declaration defines global variables. Please add static, Prevent duplicate definitions
*/
/**
*
* @param pHead1 ListNode class
* @param pHead2 ListNode class
* @return ListNode class
*/
struct ListNode* Merge(struct ListNode* pHead1, struct ListNode* pHead2 ) {
// write code here
struct ListNode dummy; // Declare pseudo header pointer
struct ListNode * cur=&dummy; //cur That is, the pseudo header pointer
while(pHead1&&pHead2){ // As long as the two linked lists are not empty , Start looking for
if(pHead1->val<=pHead2->val){ // When pHead1 The value is less than pHead2, Link it to the new linked list
cur->next=pHead1;
pHead1=pHead1->next; // Then move the linked list back 1
}
else
{
cur->next=pHead2;
pHead2=pHead2->next; // Ditto and vice versa
}
cur=cur->next;
}
cur->next=pHead1==NULL?pHead2:pHead1; // The list is empty , if 1 Empty rule link 2, Otherwise link 1, Use macro judgment
return dummy.next; Return to the head of the new linked list
}边栏推荐
- Unity shader: realize diffuse reflection and specular reflection
- ip作业(1)
- TensorFlow-GPU 安装 -- 056
- Leetcode剑指offer JZ9 双栈实现队列
- Dameng database_ Dmfldr tool instructions
- Interview questions for Test Manager / test team leader / Test Supervisor
- Openpose unity plug-in deployment tutorial
- Jenkins automated unattended operation (up / down)
- Unity shader migrated from built-in rendering pipeline to URP
- Map the intranet to the public network [no public IP required]
猜你喜欢

Basic knowledge of unity and the use of some basic APIs

IP class notes (5)

Top 10 vulnerability assessment and penetration testing tools

不租服务器,自建个人商业网站(3)

简单三步快速实现内网穿透

快速简单搭建FTP服务器,并内网穿透实现公网访问【无需公网IP】

Openpose unity plug-in deployment tutorial

Do not rent a server, build your own personal business website (how to buy a domain name)

UE4 random generation of items

Machine learning & deep learning introduction information sharing summary
随机推荐
What is monotonic queue
【217】#!/ The meaning of usr/bin/env
Li Kou 986. Intersection of interval lists
IP课笔记(5)
leetcode剑指offer JZ25 合并两个排序的链表
Remote connection to Qunhui NAS at home [no public IP, free intranet penetration]
Using keras and LSTM to realize time series prediction of long-term trend memory -lstnet
Use intranet penetration to realize public network access to the Intranet
IP notes (6)
leetcode 不用加减乘除算加法 || 二进制中1的个数
IP笔记(10)
Unity (III) three dimensional mathematics and coordinate system
Unity2d game let characters move - next
IP作业(2)RIP
Luckyframeweb testing platform (a full latitude free open source testing platform that supports interface automation, Web UI automation, APP automation, and distributed testing)
【219】app 测试和web测试的区别点?
Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]
Flink restart policy
Basic knowledge of unity and the use of some basic APIs
一个测试经理/测试主管/测试总监的工作总结