234. Palindrome Linked List
2016-03-09 20:19
190 查看
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: bool isPalindrome(ListNode* head) { if(!head||!head->next) return true; //get len ListNode* a=head; int len=0; while(a) { len++; a=a->next; } //push stack<ListNode*> s1; a=head; for(int i=0;i<len/2;i++) { s1.push(a); a=a->next; } if(len%2) a=a->next; for(int i=0;i<len/2;i++) { if(a->val==s1.top()->val) s1.pop(); a=a->next; } if(s1.size()) return false; else return true; } };
相关文章推荐
- 303. Range Sum Query - Immutable
- C++ 按指定分隔符拆分字符串
- 【清华集训2014】mex
- 清醒吧拭心!自满的程序员是最菜的!
- 判断有向图中是否有环
- JavaScript 核心基础语法
- 【数据结构】线性表(链表实现)
- 【高性能】linux加载当前目录的动态库
- 28. Implement strStr()
- need improve204. Count Primes
- Java网络编程——InetAddress
- AngularJS+Node的RESTful之基本实现
- 24点游戏&&速算24点(dfs)
- 常用网络管理操作
- [C]LeetCode:Maximum Depth of Binary Tree
- C++虚继承中的对象内存布局
- POJ 2407-Relatives-欧拉函数
- 228. Summary Ranges
- poj 2142 The Balance(扩展欧几里德算法)
- 56-题目1087:约数的个数