美文网首页
LinkedList:检查链表是否回文

LinkedList:检查链表是否回文

作者: 敲一手烂代码 | 来源:发表于2016-05-18 13:17 被阅读0次
public static boolean test5(Node node) {
        Stack<Integer> stack = new Stack<Integer>();
        Node head = node;
        while (head!=null) {
            stack.push(head.value);
            head = head.next;
        }
        
        while (!stack.isEmpty()) {
            if (stack.pop()!=node.value) {
                return false;
            }
            node = node.next;
        }
        
        return true;
    }

相关文章

  • 02-14:leetcode重刷8之哈希与数组

    链表: 判断链表是否环形、是否回文 1、是否链表 #Definitionforsingly-linkedlist....

  • LinkedList:检查链表是否回文

  • LeetCodeDay13 —— 回文链表&环形链表

    234. 回文链表 描述 请检查一个链表是否为回文链表。 进阶 你能在 O(n) 的时间和 O(1) 的额外空间中...

  • LintCode 回文链表

    题目 设计一种方式检查一个链表是否为回文链表。 样例1->2->1 就是一个回文链表。 分析 链表由于其特殊的结构...

  • 5_9链表的回文结构

    请编写一个函数,检查链表是否为回文。 给定一个链表ListNode* pHead,请返回一个bool,代表链表是否...

  • LeetCode:回文链表

    面试题 02.06. 回文链表 编写一个函数,检查输入的链表是否是回文的。示例 1:输入: 1->2输出: fal...

  • lintcode-回文链表

    设计一种方式检查一个链表是否为回文链表。再用原地反转解决一次

  • 链表的回文

    请编写一个函数,检查链表是否为回文。给定一个链表ListNode* pHead,请返回一个bool,代表链表是否为...

  • 好未来--技术笔试

    1.Java反射有几种实现方法? 2.设计一种方式检查一个链表是否为回文链表

  • LeetCode-Palindrome Linked List

    发布自Kindem的博客,欢迎大家转载,但是要注意注明出处 问题 请检查一个链表是否为回文链表。 解答 将链表存入...

网友评论

      本文标题:LinkedList:检查链表是否回文

      本文链接:https://www.haomeiwen.com/subject/hfrwrttx.html