Efficient way to check String palindrome or not in java
public class CheckPalindromEfficientWay {
public static boolean isPalindrom(String str){
int n = str.length();
for( int i = 0; i < n/2; i++ )
if (str.charAt(i) != str.charAt(n-i-1)) return false;
return true;
}
public static void main(String[] args) {
System.out.println(isPalindrom("madam"));
}
}
Comments
Post a Comment