lc234

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

README

234.回文链表

1. 题目描述

给你一个单链表的头节点 head ,请你判断该链表是否为回文链表。如果是,返回 true ;否则,返回 false

示例 1:


输入:head = [1,2,2,1]
输出:true

示例 2:


输入:head = [1,2]
输出:false

提示:

  • 链表中节点数目在范围 [1, 10^5]
  • 0 <= Node.val <= 9

进阶: 你能否用 O(n) 时间复杂度和 O(1) 空间复杂度解决此题?

标签 递归 链表 双指针

2. 解题

1.将链表的结点值转换到数组中,在判断是不是回文数
2.采用双指针,先将链表后半段反转,在比较和前半段是否相同,相同即为回文链表,最后将链表后半部分反转成原链表

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL