Pallindrome

You are given a string S.You need to check whether it's a palindrome or not. Print "YES" (without quotes) if S is a palindrome and "NO" (without quotes) if S is not a palindrome.

Example:

Input:  s = "aba"
Output: YES

Approach

C++

#include <bits/stdc++.h>
using namespace std;

bool isPalindrome(string s)
{
    int flag = 0;
    for (int i = 0i < s.size() / 2i++)
    {
        if (s[i] != s[s.size() - 1 - i])
        {
            flag = 1;
            break;
        }
    }
    if (flag)
        return false;
    else
        return true;
}
int main()
{

    string s = "aba";

    if (isPalindrome(s))
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}


No comments:

Post a Comment