当前位置:网站首页>leetcode - 234. 回文链表
leetcode - 234. 回文链表
2022-04-22 18:07:00 【zmm_mohua】
leetcode - 234. 回文链表
题目

代码
#include <iostream>
#include <vector>
using namespace std;
typedef struct ListNode{
int val;
struct ListNode *next;
}ListNode, *LinkList;
void create(LinkList &head){
int n;
cin>>n;
head = new ListNode;
head->next = NULL;
ListNode *tail = head;
for(int i = 0; i < n; i++){
ListNode *p = new ListNode;
cin>>p->val;
p->next = NULL;
tail->next = p;
tail = p;
}
}
bool isPalindrome(ListNode* head) {
vector<int> nums;
while(head){
nums.push_back(head->val);
head = head->next;
}
int left = 0, right = nums.size() - 1;
while(left <= right){
if(nums[left] != nums[right]){
return false;
}
left++;
right--;
}
return true;
}
int main(){
ListNode *head;
bool res;
create(head);
head = head->next;
res = isPalindrome(head);
if(res){
cout<<"true";
}else{
cout<<"false";
}
return 0;
}
版权声明
本文为[zmm_mohua]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_42250642/article/details/124342706
边栏推荐
- In 2022, it is said on the Internet that Apple's upcoming new models iPhone 14 pro and iPhone 14 Pro Max will be a new screen shape, not a banged screen. Do you expect the iPhone 14 with a new screen
- Soft test high item notes | project schedule management
- Notes on soft test high items | contents of feasibility study
- Overview of cement data in Guangdong
- 富文本编辑器导出内容为pdf或docx
- Pikachu File Inclusion (File Inclusion Vulnerability)
- Activiti 挂起与激活任务
- The USB flash disk cannot be recognized when it is inserted into the computer. How to solve it?
- B树[概念]
- 电脑上怎么快速切换显示不同的软件界面
猜你喜欢

Soft test high item notes | PERT three-point estimation

leetcode 111:二叉树的最小深度

Dynamic programming: multiple knapsack problem

Soft test high item notes | demand classification

Use of ES6 generator function

Second Cloud a aidé la solution SaaS Cloud Management Platform basée sur un cadre d'intégration d'applications simulé publié par le CETC 32

Multithreaded notes | future interface function

优麒麟 22.04 LTS 版本正式发布 | UKUI 3.1开启全新体验!

Unable to translate SQLException with Error code ‘0‘, will now try the fallback translator

es6 Generator函数的使用
随机推荐
秒云助力中电科32所发布“基于拟态应用集成框架的SaaS云管理平台解决方案”
【Lane】Ultra-Fast-Lane-Detection(2)自定义模型测试
leetcode 108:将有序数组转换为二叉搜索树
解读《全面提升江苏数字经济发展水平的指导意见》七大重点任务
How do I completely delete files on my computer?
APP应该关注哪些数据指标?
手机运行内存应该怎么选?
必刷|2022年江西最新八大员之(安全员)模拟题库及答案
如何彻底删除电脑上的文件?
PiKachu-File Inclusion(文件包含漏洞)
Common libraries for video playback
B-tree [concept]
Leetcode 111: minimum depth of binary tree
Domestic chip dp9637-k bus transceiver replaces l9637d chip and si9241
Must brush the simulated question bank and answers of the latest eight members of Jiangxi in 2022
【C语言进阶篇】一篇文章带你认清结构、枚举和联合
多次调用 BAPI 之后,最后一次性 COMMIT WORK,会有什么问题吗?
Esp32 Ethernet throughput performance peak challenge test notes
Read and write txt files in C language
Interface test mock practice (II) | complete batch manual mock in combination with JQ