diff --git a/Palindrome String Problem of IB in CPP b/Palindrome String Problem of IB in CPP new file mode 100644 index 0000000..a0a81c3 --- /dev/null +++ b/Palindrome String Problem of IB in CPP @@ -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; +}