Vector based solution checkout


#1

ListNode* Solution::solve(ListNode* A) {
ListNode* temp = A;
vectorv{};
int n=0;
while(temp!=NULL)
{
if((n+1)%2==0)
v.push_back(temp->val);
temp=temp->next;
n++;
}
if(n<4)return A;
reverse(v.begin(),v.end());
temp = A;
for(int i=0,j=0;i<n;i++)
{
if((i+1)%2==0)
{
temp->val=v[j];
j++;
}
temp=temp->next;
}

return A;
}


#2

can we use these kind of silution in interviews because i also solved this similarly as you