leetcode

package
v0.0.0-...-3200de1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2023 License: MIT Imports: 1 Imported by: 0

README

234. Palindrome Linked List

题目

Given a singly linked list, determine if it is a palindrome.

Example 1:

Input: 1->2
Output: false

Example 2:

Input: 1->2->2->1
Output: true

Follow up:

Could you do it in O(n) time and O(1) space?

题目大意

判断一个链表是否是回文链表。要求时间复杂度 O(n),空间复杂度 O(1)。

解题思路

这道题只需要在第 143 题上面改改就可以了。思路是完全一致的。先找到中间结点,然后反转中间结点后面到结尾的所有结点。最后一一判断头结点开始的结点和中间结点往后开始的结点是否相等。如果一直相等,就是回文链表,如果有不相等的,直接返回不是回文链表。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func L2ss

func L2ss(head *ListNode) []int

L2ss define

Types

type ListNode

type ListNode = structures.ListNode

ListNode define

Jump to

Keyboard shortcuts

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