Leetcode Palindrome Number problem solution in C programming

In the Leetcode Palindrome Number problem solution in C programming Given an integer x, return true if x is a palindrome, and false otherwise.

Leetcode Palindrome Number problem solution in C programming

bool isPalindrome(int x){
    int count = 0;
    int* arr = (int*)malloc(sizeof(int)*15);
    int i =0;
    if(x >= 0)
    {
        while( x != 0)
        {
            arr[count] = x%10;
            x = x/10;
            count++;
        }
        for(i=0;i<count/2;i++)
        {
            if(arr[i] != arr[count-i-1])
            {
                return false;
            }
        }
    }
    else
    {
        return false;
    }
    return true;

}

Also read,

By Neha Singhal

Hi, my name is Neha singhal a software engineer and coder by profession. I like to solve coding problems that give me the power to write posts for this site.

Leave a Reply

Your email address will not be published. Required fields are marked *