Advertisement
enigmjoe

Big O week 3 day 5 p2

Sep 1st, 2023
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. /****************************************************************
  3.  
  4. Following is the class structure of the LinkedListNode class:
  5.  
  6. template <typename T>
  7. class LinkedListNode
  8. {
  9. public:
  10. T data;
  11. LinkedListNode<T> *next;
  12. LinkedListNode(T data)
  13. {
  14. this->data = data;
  15. this->next = NULL;
  16. }
  17. };
  18.  
  19. *****************************************************************/
  20.  
  21. bool isPalindrome(LinkedListNode<int> *head) {
  22. LinkedListNode<int>* tmp = head;
  23. vector<int> v;
  24. while(tmp){
  25. v.push_back(tmp->data);
  26. tmp=tmp->next;
  27. }
  28. vector<int> w=v;
  29. reverse(w.begin(),w.end());
  30. return v == w;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement