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 = 0; i < s.size() / 2; i++){if (s[i] != s[s.size() - 1 - i]){flag = 1;break;}}if (flag)return false;elsereturn true;}int main(){string s = "aba";if (isPalindrome(s))cout << "YES\n";elsecout << "NO\n";return 0;}
No comments:
Post a Comment