string longestPalindrome(string s) {
     // Note: The Solution object is instantiated only once and is reused by each test case.
     int start = 0, length = 0;
     for(int i=0; i<s.size(); i++)
     {
         checkPalindrome(s, i-1, i+1, start, length); // at s[i]
         
         if(i+1 < s.size() && s[i] == s[i+1]) // at s[i] & s[i+1]
             checkPalindrome(s, i-1, i+2, start, length); 
     }
     
     return s.substr(start, length);
 }
Exemple #2
0
int main(){
    ListNode* head = new ListNode(1);
    addNode(head, 2);
    addNode(head, 2);
    addNode(head, 1);
    printList(head);
    cout << checkPalindrome(head) << endl;
}
 bool isPalindrome(ListNode* head) {
     int len=count(head);
     if(len==0 || len==1)
         return true;
     if(len==2)
         return (head->val == head->next->val)?true:false;
     return checkPalindrome(head,len);
 }
Exemple #4
0
int main(int argc, char * argv[])
{
  List * list = NULL;

  createPalindrome(&list);
  printList(list);
  checkPalindrome(list);
  freeList(list);

  list = NULL;

  createNonPalindrome(&list);
  printList(list);
  checkPalindrome(list);
  freeList(list);

  return(0);
}
Exemple #5
0
int addEleven(int number){
	double x = 10.0;
	number = number + 11;
	int numOfDigits = findNumberOfDigits(number);
	int firstDigit = number/(int)ceil(pow(x,(double)(numOfDigits-1)));
	int lastDigit = number%10;
	number = number + firstDigit - lastDigit;
	
	if(checkPalindrome(number)==1){
		return number;
	} else
		return addEleven(number);
		
}
Exemple #6
0
int main6 (){
	int number;
	while(1){
		printf("Enter Number  whose next palidrome has to be found: ");
		scanf("%d",&number);
		if(number == -1)
			break;
		if(checkPalindrome(number) == 1)
			printf("isPalidrome=true\n");
		else
			printf("Next Palindrome is %d\n",findNextPalindrome(number));
	}
	
	return 0;
}
Exemple #7
0
int checkPalindrome(int number){
	double x = 10;
	if(number/10 == 0)
		return 1;
	int numOfDigits = findNumberOfDigits(number);
	
	if(numOfDigits == 2){
		if(number%11== 0)
			return 1; 
	}
	
	if(number/(int)pow(x,(double)(numOfDigits-1)) != number%10)
		return 0;
	number = number - ((number%10)*(int)pow(x,(double)(numOfDigits-1)) + number%10);
	number = number/10;
	return checkPalindrome(number);
}
Exemple #8
0
int main() {
    int res, i, j, sum;
    int s[21] = {0};
    sum = 0;
    for (i=1; i<LIMIT; i++) {
        res = checkPalindrome(i);
        if (res) {
            dec2bin(i, s);
            if (checkPalindromeBin(s)) {
                sum += i;
            }
        }
    }

    printf("sum is %d\n", sum); //872187
    
    return 0;
}
int main() 
{
	std::string str("Tact Coa");
	std::vector<int> v;

	convertToLowerCase(str);
	getCharFrequency(v, str);
	
	if(checkPalindrome(v)) 
	{
		std::cout << "there is palindrome permutations in this string" << std::endl;
	}
	else 
	{
		std::cout << "there is not palindrome permutations in this string" << std::endl;
	}

	return 0;
}
int main() {
    int largestNumber = 0;

    int x;
    int i;
    int j;
    for(i = 999; i > 100; i--) {
        for(j = 999; j > 100; j--) {
            x = i * j;

            if (checkPalindrome(x) == 1) {
                if (x > largestNumber) {
                    largestNumber = x;
                }
            }
        }
    }

    printf("%d", largestNumber);
}
int main(){

	node_t *head1 = NULL;
		
	int len1 = 0;
	int len2 = 0;
	//insertElement(1,&head1);
	insertElement(2,&head1);
	insertElement(4,&head1);
	insertElement(2,&head1);
	insertElement(1,&head1);

	int mid = returnIndex(head1);
	
	checkPalindrome(&head1,mid);
	
	
	
	return 0;
}
Exemple #12
0
int main(void)
{
    NODE *start=NULL,*temp=NULL;
    insert(&start,10);
    insert(&start,20);
    insert(&start,30);
    insert(&start,40);
    insert(&start,30);
    insert(&start,20);
    insert(&start,10);
    insert(&temp,11);
    insert(&temp,12);
    insert(&temp,13);
    insert(&temp,14);
    display(start);
    if(checkPalindrome(start))
        printf("\nPalindrome");
    else
        printf("\n not palindrome");
    return 0;
}
void palindromeIndex(const std::string& str) {
	// Let's create a copy of our string
	std::string palString(str);

	// First we can check if the string is empty
	if (palString.empty())
		return;

	// Now we can create a variable for length
	int length = palString.length();

	// And a variable to track the index
	int index = -1;

	// We can set our characters that we will traverse with
	char start = 0;
	char end = length - 1;

	
	while (start < end) {
		// If current characters don't match
		if (tolower(palString[start]) != tolower(palString[end])) {
			// Create a substring and check if a palindrome exists
			if (checkPalindrome(palString.substr(start + 1, end + 1)) == true) {
				index = start;
				std::cout << index << std::endl;
				return;
			}
			else {
				index = end;
				std::cout << index << std::endl;
				return;
			}
		}
		start++;
		end--;
	}
	std::cout << index << std::endl;
	return;
}
bool checkPalindrome(string word, int firstPos, int lastPos) {
	if(firstPos >= lastPos) return true;
	return ((word[firstPos] == word[lastPos]) && checkPalindrome(word, firstPos+1, lastPos-1));
}
bool efficientIsPalindromeRecursive(std::string word) {
	return checkPalindrome(word, 0, word.length() - 1);
}