Palindrome String
Problem Statement
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
Task
You don't need to read input or print anything. Complete the function isPalindrome() which accepts string S and returns an integer value 1 or 0.
Expected Time Complexity : O(Length of S).
Expected Auxiliary Space : O(1).
Constraints :
1 <= Length of S <= 105
Solutions
Java Solution
class Solution {
int isPalindrome(String S) {
// code here
String rev="";
for(int i=S.length()-1; i>=0; i--) {
rev = rev + S.charAt(i);
}
if(S.equals(rev)) {
return 1;
}
return 0;
}
};
0 Comments