problem no 29:(string problem):palindrome string.

 QUESTION:

Given a string S, check if it is palindrome or not.

Example 1:

Input: S = "abba"
Output: 1
Explanation: S is a palindrome

Example 2:

Input: S = "abc" 
Output: 0
Explanation: S is not a palindrome

 

ANSWER:

 int isPlaindrome(String S) {
        String ss="";
        for(int i=S.length()-1;i>=0;i--)
        {
            ss=ss+S.charAt(i);
        }
        int flagforbeingpalindrome=1;
        for(int i=0;i<S.length();i++)
        {
            if(S.charAt(i)!=ss.charAt(i))
            {
                flagforbeingpalindrome=0;
            }
        }
        if(flagforbeingpalindrome==0)
        {
            return 0;
        }
        else
        {
            return 1;
        }
       
    }


Comments

Popular posts from this blog

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.

problem no 7:Given two numbers A and B, find Kth digit from right of AB.

Problem no 16: count the number of squares below N.