Hamoudi30

Untitled

Nov 7th, 2021 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct Node {
  4. int data;
  5. struct Node *next;
  6. };
  7. void push(struct Node** head, int data) {
  8. struct Node *newNode = (struct Node *) malloc(sizeof(struct Node));
  9. newNode->data = data;
  10. newNode->next = *head;
  11. *head = newNode;
  12. }
  13. int checkPalindrome(struct Node** left, struct Node* right) {
  14. if (right == NULL) {
  15. return 1;
  16. }
  17. int result = checkPalindrome(left, right->next) && ((*left)->data == right->data);
  18. (*left) = (*left)->next;
  19. return result;
  20. }
  21. int main(void) {
  22. struct Node *head = NULL;
  23. long long n;
  24. scanf("%lld", &n);
  25. if (n < 10) {
  26. printf("YES");
  27. return 0;
  28. }
  29. while (n > 0) {
  30. push(&head, n % 10);
  31. n /= 10;
  32. }
  33. printf(checkPalindrome(&head, head) ? "YES" : "NO");
  34. return 0;
  35. }
Add Comment
Please, Sign In to add comment