linked list of strings forms a palindrome || GFG POTD today || 2 july || easy
ฝัง
- เผยแพร่เมื่อ 30 มิ.ย. 2024
- time complexity :[ O(n) using a loop to iterate over the linked list]
space complexity :[O(n) storing the whole linked list into a string ]
**check comments for solution
#dailychallenge #coding #gfgpotd #gfg #easy #datastructures
class Solution {
public:
bool compute(Node* head) {
string str = "";
string copy;
while(head!=NULL){
str += head->data;
head= head->next;
}
copy=str;
reverse(copy.begin(),copy.end());
if(copy==str)return true;
return false;
}
};