-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create LinkedListStringPalindrome.cpp
- Loading branch information
1 parent
d4f1a2d
commit 11be90e
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
}; |