反转链表
2025-4-20
| 2025-4-20
Words 286Read Time 1 min
type
status
date
slug
summary
tags
category
icon
password

题目:

给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/SNJvJP 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
示例 1:
notion image
rev1ex1
示例 2:
notion image
rev1ex2
示例 3:
提示:
  • 链表中节点的数目范围是 [0, 5000]
  • 5000 <= Node.val <= 5000

思路:

  • 既然是翻转链表,那么在遍历的时候就把指针同时倒过来,每遍历一个就把指针倒过来,这样,遍历完成之后,指针就全部反转了。

代码:

结果:

notion image
image-20220408160958570
句子中的最多单词数反转字符串中的单词
Loading...