链表题目汇总(反转链表 回文链表 链表中点)

目录
链表全部反转
链表从m到n反转
链表中点
回文链表

反转链表是面试中经常会问到的题目,可以作为模板理解后记忆。
主要有两道,一个是将一个链表全部反转,一个是将链表的m到n个节点反转。
这些模板可以应用在很多题目中比如
234. 回文链表https://leetcode-cn.com/problems/palindrome-linked-list/

 
链表全部反转
public class Solution {
public ListNode ReverseList(ListNode head) {
if(head==null) return head;
ListNode cur = head;// cur指向当前节点
ListNode pre = null;// pre保存上一个节点 遍历时将cur指向pre即可
while(cur != null){
ListNode nextNode = cur.next;

链表题目汇总(反转链表 回文链表 链表中点)最先出现在Python成神之路

版权声明:
作者:congcong
链接:https://www.techfm.club/p/22416.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>