Problem: Implement a function to check if a singly linked list is a palindrome.

思路:

最简单的方法是 Reverse and compare.

另外一种非常经典的办法是用 Recursive 的思路,把一个list看成这种形式:

0 ( 1 ( 2 ( 3 ) 2 ) 1 ) 0

0 ( 1 ( 2 ( 3 3 ) 2 ) 1 ) 0

CC150里面给出的Code,非常简洁,贴在下面:

length == 1 对应上面第一种情况

length == 2 对应上面第二种情况

其中用到了一个Wrapper class 'Result', 因为Java不支持返回值传两个变量。

class Result{
  LinkedListNodde node;
  boolean result;
}

[cc150] check palindrome of a singly linked list的更多相关文章

  1. Singly Linked List

    Singly Linked List Singly linked list storage structure:typedef struct Node{ ElemType data; struct N ...

  2. LeetCode 206 Reverse a singly linked list.

    Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. ...

  3. [LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点

    Implement an algorithm to delete a node in the middle of a singly linked list, given only access to ...

  4. Reverse a singly linked list

    Reverse a singly linked list. /** * Definition for singly-linked list. * struct ListNode { * int val ...

  5. 单链表反转(Singly Linked Lists in Java)

    单链表反转(Singly Linked Lists in Java) 博客分类: 数据结构及算法   package dsa.linkedlist; public class Node<E> ...

  6. [TS] Implement a singly linked list in TypeScript

    In a singly linked list each node in the list stores the contents of the node and a reference (or po ...

  7. [轉]Reverse a singly linked list

    Reverse a singly linked list  http://angelonotes.blogspot.tw/2011/08/reverse-singly-linked-list.html ...

  8. Data Structure Linked List: Function to check if a singly linked list is palindrome

    http://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/ 这里的reverse可以re ...

  9. Singly linked list algorithm implemented by Java

    Jeff Lee blog:   http://www.cnblogs.com/Alandre/  (泥沙砖瓦浆木匠),retain the url when reproduced ! Thanks ...

随机推荐

  1. Redis - 环境的安装配置

    Redis 下载安装步骤: 下载 redis 源码: [huey@huey-K42JE ~]$ wget http://download.redis.io/releases/redis-x.y.z.t ...

  2. Warrior!之家与Warrior!博客网站发布

    这个网站从大一下学期就开始做,断断续续,一开始感觉无从下手,做了一个草稿便停止了.最近再拿回来,感觉并没有什么难度,便把它做完了,采用ajax页内跳转,对几个搜索引擎都有seo,目前谷歌搜索“Warr ...

  3. winform 渐变(非API)

    public FrmMain() { InitializeComponent(); //窗体显示特效 Opacity = 0.0; //窗体透明度为0 fadeTimer.Start(); //计时开 ...

  4. 你不知道的JSON的高效率用法

    1.JSON JSON是JavaScript Object Notation的缩写,是JavaScript标准的一个子集.官方Android API已经内置支持读写JSON数据.这种格式非常适合表示不 ...

  5. 【Android】日常开发android.jar文件中十五个重要的包概述

    简述Android项目中android.jar文件里包含较为重要的15个系统编译后的class文件 android.app:提供高层的程序模型,提供基本的运行环境android.content:包含各 ...

  6. PLSQL插入数据中文乱码的问题

    PLSQL插入数据中文乱码的问题 中文乱码就是编码不统一所导致的了,解决办法只需要把编码统一下即可解决了. 具体操作步骤如下: 1.查看服务器端编码 select userenv('language' ...

  7. DB2查看表空间大小及使用情况

    1.SQL 查询(选择Schema为SYSPROC) SELECT SUBSTR(TABLESPACE_NAME,,) AS TBSPC_NAME, AS "TOTAL(MB)", ...

  8. iOS - 文件操作(File Operating)

    1. 沙盒 & NSData /*_______________________________获取沙盒路径_________________________________________* ...

  9. des算法的C#实现

    DES是Data Encryption Standard(数据加密标准)的缩写.它是一种通过56位密钥来加密64位数据的方法. public class EncryptUtility{    #reg ...

  10. VxWorks 6.9 内核编程指导之读书笔记 -- VxWorks Small-Footprint Configuration

    什么是Small-footprint? Small-footprint常见关键配置? 如何配置Small-footprint? 什么是Small-footprint? Small-footprint配 ...