We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
byC:intpalindromeIndex(char*s){intlen=0,left=0,right=len-1,tempLeft=0,tempRight=len-1;if(s!=NULL){while(s[len]!='\0')len++;right=len-1;tempRight=len-1;// normal checkingwhile(left<right&&(s[left]==s[right])){left++;right--;}if(left>=right)return-1;// try to skip lefttempLeft=left++;tempRight=right;while(left<right&&(s[left]==s[right])){left++;right--;}if(left>=right)returntempLeft;// try to skip right ,BUT need first to back to the old valueleft=tempLeft;right=tempRight-1;while(left<right&&(s[left]==s[right])){left++;right--;}if(left>=right)returntempRight;elsereturn-1;// so no solution for this string}else{return-1;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Palindrome Index
You are viewing a single comment's thread. Return to all comments →