Skip to content

Commit

Permalink
Create LinkedListStringPalindrome.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitiz11101 authored Jul 2, 2024
1 parent d4f1a2d commit 11be90e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Linked Lists/LinkedListStringPalindrome.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

/*
The structure of linked list is the following
struct Node
{
string data;
Node* next;
Node(int x){
data = x;
next = NULL;
}
};
*/
class Solution {
public:
bool compute(Node* head) {
// Your code goes here
string ans="";

Node*curr=head;
while(curr!=NULL){
ans+=curr->data;
curr=curr->next;
}
int n=ans.size();
for(int i=0;i<n/2;i++){
if(ans[i]!=ans[n-i-1]){
return false;
}
}
return true;

}
};

0 comments on commit 11be90e

Please sign in to comment.