Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Node {
- int data;
- struct Node *next;
- };
- void push(struct Node** head, int data) {
- struct Node *newNode = (struct Node *) malloc(sizeof(struct Node));
- newNode->data = data;
- newNode->next = *head;
- *head = newNode;
- }
- int checkPalindrome(struct Node** left, struct Node* right) {
- if (right == NULL) {
- return 1;
- }
- int result = checkPalindrome(left, right->next) && ((*left)->data == right->data);
- (*left) = (*left)->next;
- return result;
- }
- int main(void) {
- struct Node *head = NULL;
- long long n;
- scanf("%lld", &n);
- if (n < 10) {
- printf("YES");
- return 0;
- }
- while (n > 0) {
- push(&head, n % 10);
- n /= 10;
- }
- printf(checkPalindrome(&head, head) ? "YES" : "NO");
- return 0;
- }
Add Comment
Please, Sign In to add comment