首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
判断一个链表是否为回文结构
[编程题]判断一个链表是否为回文结构
热度指数:206615
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给定一个链表,请判断该链表是否为回文结构。
回文是指该字符串正序逆序完全一致。
数据范围: 链表节点数
,链表中每个节点的值满足
示例1
输入
{1}
输出
true
示例2
输入
{2,1}
输出
false
说明
2->1
示例3
输入
{1,2,2,1}
输出
true
说明
1->2->2->1
说明:本题目包含复杂数据结构ListNode,
点此查看相关信息
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(6)
邀请回答
收藏(599)
分享
提交结果有问题?
0个回答
435篇题解
添加回答
这道题你会答吗?花几分钟告诉大家答案吧!
提交观点
问题信息
链表
双指针
难度:
0条回答
599收藏
9263浏览
热门推荐
通过挑战的用户
查看代码
洞洞鞋小公主
2023-03-13 10:58:26
牛客20133...
2023-03-12 12:59:31
成熟的肖恩在创作
2023-03-01 16:03:58
K乀
2023-02-25 17:20:23
少糖加蛋娃哈哈
2023-02-24 16:34:26
相关试题
神奇的数字
排序
双指针
评论
(46)
和为S的两个数字
数组
数学
双指针
评论
(1511)
来自
“一战通offer”互联...
最小面积子矩阵
动态规划
双指针
前缀和
评论
(44)
编译方法中,动态存储分配的含义是:()
编译和体系结构
评论
(2)
来自
乐视2017秋招开发工程...
闪速存储器能提供高性能、低功耗、字...
编程基础
评论
(1)
判断一个链表是否为回文结构
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; /* * public class ListNode { * int val; * ListNode next = null; * public ListNode(int val) { * this.val = val; * } * } */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ public boolean isPail (ListNode head) { // write code here } }
/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : val(x), next(nullptr) {} * }; */ class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ bool isPail(ListNode* head) { // write code here } };
#coding:utf-8 # class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param head ListNode类 the head # @return bool布尔型 # class Solution: def isPail(self , head ): # write code here
using System; using System.Collections.Generic; /* public class ListNode { public int val; public ListNode next; public ListNode (int x) { val = x; } } */ class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ public bool isPail (ListNode head) { // write code here } }
/* * function ListNode(x){ * this.val = x; * this.next = null; * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ function isPail( head ) { // write code here } module.exports = { isPail : isPail };
val = $x; } }*/ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ function isPail( $head ) { // write code here }
# class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param head ListNode类 the head # @return bool布尔型 # class Solution: def isPail(self , head: ListNode) -> bool: # write code here
package main import "fmt" import . "nc_tools" /* * type ListNode struct{ * Val int * Next *ListNode * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ func isPail( head *ListNode ) bool { // write code here }
/** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ bool isPail(struct ListNode* head ) { // write code here }
# class ListNode # attr_accessor :val, :next # # def initialize(val = 0, _next = nil) # @val, @next = val, _next # end # end # # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param head ListNode类 the head # @return bool布尔型 # class Solution def isPail(head) # write code here end end
/** * class ListNode(var val: Int) { * var next: ListNode = null * } */ object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ def isPail(head: ListNode): Boolean = { // write code here } }
/** * class ListNode(var `val`: Int) { * var next: ListNode? = null * } */ object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ fun isPail(head: ListNode?): Boolean { // write code here } }
import java.util.*; /* * public class ListNode { * int val; * ListNode next = null; * public ListNode(int val) { * this.val = val; * } * } */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ public boolean isPail (ListNode head) { // write code here } }
/*class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ export function isPail(head: ListNode): boolean { // write code here }
/** * public class ListNode { * public var val: Int * public var next: ListNode? * public init(_ val: Int = 0, _ next: ListNode? = nil) { * self.val = val * self.next = next * } * } */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ func isPail ( _ head: ListNode?) -> Bool { // write code here } }
/** * #[derive(PartialEq, Eq, Debug, Clone)] * pub struct ListNode { * pub val: i32, * pub next: Option
> * } * * impl ListNode { * #[inline] * fn new(val: i32) -> Self { * ListNode { * val: val, * next: None, * } * } * } */ struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ pub fn isPail(&self, head: Option
>) -> bool { // write code here } }
{1}
true
{2,1}
false
{1,2,2,1}
true