回文链表 -LintCode
来源:互联网 发布:精米刻录机mac驱动 编辑:程序博客网 时间:2024/06/05 00:51
设计一种方式检查一个链表是否为回文链表。
样例:
1->2->1 就是一个回文链表。
挑战 :
O(n)的时间和O(1)的额外空间。
#ifndef C233_H#define C233_H#include<iostream>#include<vector>using namespace std;struct ListNode{ int val; ListNode *next; ListNode(int x) :val(x), next(NULL) {}};class Solution {public: /* * @param head: A ListNode. * @return: A boolean. */ bool isPalindrome(ListNode * head) { // write your code here if (head == NULL) return true; vector<int> v; ListNode *p = head; while (p != NULL) { v.push_back(p->val); p = p->next; } int l = 0; int r = v.size() - 1; while (l < r) { if (v[l] != v[r]) { return false; break; } ++l; --r; } return true; }};#endif
阅读全文
0 0
- LintCode:回文链表
- LintCode:回文链表
- lintcode,回文链表
- LintCode 回文链表
- 回文链表-LintCode
- lintcode--回文链表
- 回文链表 -LintCode
- lintcode-回文链表-223
- [LintCode]223.回文链表
- lintcode-有效回文字符串
- LintCode : 有效回文串
- LintCode-有效回文串
- lintcode刷题--回文串
- LintCode- 分割回文串
- lintcode --有效回文串
- 最长回文字串 lintcode
- LintCode:回文串
- LintCode:分割回文串
- WebApi HTTP Put 405 Method not allowed
- 开启和查看mysql的bin-log日志-mysql
- Window环境下配置Nginx集群(一)
- 常用类——日期
- java通过电话号码获取归属地,区号,邮编
- 回文链表 -LintCode
- Linux下常用的SSH命令
- 原来你是这样的概念图
- 数据库大型应用解决方案总结
- 南阳oj 58 bfs入门
- JavaScript基础之动画
- Python 元组 列表
- 慎用select
- Java整理笔记之有理数的类封装