You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int right =str.length()-1; // last character of string .
while(left<right){ // Compare characters from both ends
if(str.charAt(left)!=str.charAt(right)){
return false;
}
left++; //left increment
right--; //right decrement.
}
return true; //i.e all character mathes.
}
}
//馃憠馃徎馃憠馃徎馃憠馃徎 time complexity= O(n);
//馃憠馃徎馃憠馃徎馃憠馃徎space complexity= O(1);
//馃憠馃徎馃憠馃徎馃憠馃徎logic =
//1.The key logic is the use of two pointers (left and right) to compare characters from both ends of the string and progressively move toward the center.
//2.If all characters match, the string is a palindrome. If any pair of characters does not match, the string is not a palindrome.