当前位置:网站首页>206. 反转链表
206. 反转链表
2022-06-11 08:55:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:206. 反转链表
描述:给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。
解题思路
1、链表反转常用代码,迭代;
2、反转之后pre就成了头结点了,所以直接返回pre就行;
原代码##
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode * pre = nullptr;
ListNode *cur = head;
while (cur) {
ListNode *temp = cur->next;
cur->next = pre;
pre = cur;
cur = temp;
}
return pre;
}
};
边栏推荐
猜你喜欢

Create a nodejs based background service using express+mysql

leetcode - 230. The k-th smallest element in a binary search tree

Intelligent control theory question bank

Getting started with Zipkin

剑指 Offer 10- II. 青蛙跳台阶问题

【C语言-数据存储】数据在内存中是怎样存储的?

哪些Apple设备支持这次系统更新?来看你的旧Apple设备支持最新系统吗

马志强:语音识别技术研究进展和应用落地分享丨RTC Dev Meetup

Android interview transcript (carefully sorted out)

你所不知道的console
随机推荐
Complete ES6 questions
Matlab学习7-图像处理之线性平滑滤波
使用express+mysql创建一个基于nodejs的后台服务
How many items should the indoor intumescent fire retardant coating meet according to BS 476-21 fire resistance standard?
Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?
Hibernate L2 cache
leetcode - 230. The k-th smallest element in a binary search tree
String类为何final修饰
【Image Processing】空间域图像增强
En45545-2 R26 vertical combustion test introduction
木板ISO 5660-1 热量释放速率摸底测试
领导让我重写测试代码,我也要照办嘛?
682. 棒球比赛
js 中 Map 和 Set 的用法及区别
Cron expressions in scheduled tasks
File system check of the root filesystem failed
SAP abap 字段符号
[node] NPM part
EN 45545-2T10水平法烟密度检测的注意事项
win10家庭版如何连接远程桌面