Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Palindrome String Problem of IB in CPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Problem Statement :

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Example:

"A man, a plan, a canal: Panama" is a palindrome.

"race a car" is not a palindrome.

Return 0 / 1 ( 0 for false, 1 for true ) for this problem



Solution :


int Solution::isPalindrome(string A) {
int i = 0, j = A.length();

for(int a = 0; a < j; a++){
A[a] = (char) tolower(A[a]);
}

while(i < j){
if((A[i] >= 'a' && A[i] <= 'z') || (A[i] >= '0' && A[i] <= '9')){
if((A[j] >= 'a' && A[j] <= 'z') || (A[j] >= '0' && A[j] <= '9')){
if(A[i] == A[j]){
i++;
j--;
}
else return 0;
}
else{
j--;
}
}
else{
i++;
}
}

return 1;
}