zoukankan      html  css  js  c++  java
  • 【leetcode】回文链表

    编写一个函数,检查输入的链表是否是回文的。

    示例 1:

    输入: 1->2
    输出: false
    示例 2:

    输入: 1->2->2->1
    输出: true

    bool isPalindrome(struct ListNode* head){
        if (!head) return true;
        int arr[100000] = {0};
        int pst=0;
        while(head)
        {
            arr[pst++] = head->val;
            head = head->next;
        }
        for (int i=0; i<=pst/2; i++)
        {
            if (arr[i] != arr[pst-1-i]) return false;
        }
        return true;
    }


     

  • 相关阅读:
    代理模式
    适配器模式
    原型模式
    创建者模式
    装饰模式
    web总结
    4.14
    4.14
    POJ2385
    POJ2229
  • 原文地址:https://www.cnblogs.com/ganxiang/p/13661971.html
Copyright © 2011-2022 走看看