当前位置:网站首页>Reverse linked list
Reverse linked list
2022-06-12 05:29:00 【cbdgz】
Punch in one question every day
2020.12.20
Enter a linked list , After reversing the list , Output the header of the new linked list .
Their thinking :
In fact, it is a stack like method , Press each point of the original list into the new list like a stack ( For the convenience of understanding, I said the new linked list , But it doesn't actually create a new linked list ).
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode *ansLink=NULL;
ListNode *cur=pHead;
ListNode *nex=NULL;
while(NULL!=cur)
{
nex=cur->next;
cur->next=ansLink;
ansLink=cur;
cur=nex;
}
return ansLink;
}
};
边栏推荐
- When the build When gradle does not load the dependencies, and you need to add a download path in libraries, the path in gradle is not a direct downloadable path
- MySQL5.7.21 Build For ARM
- Nature | 给全球的新冠伤亡算一笔账
- A solution for PHP to implement image login verification code
- Link: fatal error lnk1168: cannot open debug/test Solution of exe for writing
- 59 - II. Maximum value of the queue
- 29. print matrix clockwise
- WiFi band resources
- Ray. Tune visual adjustment super parameter tensorflow 2.0
- Detailed tutorial on the use of yolov5 and training your own dataset with yolov5
猜你喜欢

Detailed analysis of the 2021 central China Cup Title A (color selection of mosaic tiles)

Matlab: halftone and dither conversion

Wireshark filter rule

Deep understanding of asynchronous programming

Computer network connected but unable to access the Internet

Codec of ASoC framework driven by alsa

Detailed usage of vim editor

How Wireshark decrypts WiFi data packets

How to count the total length of roads in the region and draw data histogram

Stm32f4 ll library multi-channel ADC
随机推荐
Overview of common classes
19. regular expression matching
Analysis of pointer
How long is the company's registered capital subscribed
关于架构(排名不分先后)
Performance test - Analysis of performance test results
Redis cluster cluster capacity expansion and data migration
It costs less than 30 yuan, but we still don't build it quickly - check the small knowledge of software application
12.26 exercise summary
How Bi makes SaaS products have a "sense of security" and "sensitivity" (Part I)
JS how to get the date
Codis 3. X expansion and contraction
Nature | 给全球的新冠伤亡算一笔账
44. a digit in a sequence of digits
week7
How to count the total length of roads in the region and draw data histogram
Detailed tutorial on the use of yolov5 and training your own dataset with yolov5
Necessary for Test Engineer -- package capturing tool fiddler
JS to determine whether the tags of multiple classes are empty
Some optimization methods for UI Application of Qt5 on Hisilicon security platform