palindrome linked list my submissions question

Given a singly linked list, determine if it is a palindrome.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
bool (struct ListNode* head) {
int a [1000000];

int count=0;
while(head){
a[count]=head->val;

head=head->next;
count++;
}
int flag=0;
int cishu=count/2;
for(int i=0;i<cishu;i++){
if(a[i]!=a[count-i-1]){
flag=1;
break;
}
}
if(flag==1){
return false;
}
return true;
}