palindrome

Write a function that returns the longest palindrome in a given string

自古美人都是妖i 提交于 2019-11-26 11:03:19
e.g "ccddcc" in the string "abaccddccefe" I thought of a solution but it runs in O(n^2) time Algo 1: Steps: Its a brute force method Have 2 for loops for i = 1 to i less than array.length -1 for j=i+1 to j less than array.length This way you can get substring of every possible combination from the array Have a palindrome function which checks if a string is palindrome so for every substring (i,j) call this function, if it is a palindrome store it in a string variable If you find next palindrome substring and if it is greater than the current one, replace it with current one. Finally your

how to find longest palindromic subsequence?

。_饼干妹妹 提交于 2019-11-26 10:17:10
问题 Here is the problem (6.7 ch6 ) from Algorithms book (by Vazirani) that slightly differs from the classical problem that finding longest palindrome. How can I solve this problem ? A subsequence is palindromic if it is the same whether read left to right or right to left. For instance, the sequence A,C,G,T,G,T,C,A,A,A,A,T,C,G has many palindromic subsequences, including A,C,G,C,A and A,A,A,A (on the other hand, the subsequence A,C,T is not palindromic). Devise an algorithm that takes a sequence

Check string for palindrome

谁说胖子不能爱 提交于 2019-11-26 01:19:50
问题 A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction. To check whether a word is a palindrome I get the char array of the word and compare the chars. I tested it and it seems to work. However I want to know if it is right or if there is something to improve. Here is my code: public class Aufg1 { public static void main(String[] args) { String wort = \"reliefpfpfeiller\"; char[] warray = wort.toCharArray(); System.out.println

How to check that a string is a palindrome using regular expressions? [closed]

馋奶兔 提交于 2019-11-26 01:14:12
That was an interview question that I was unable to answer: How to check that a string is a palindrome using regular expressions? p.s. There is already a question " How to check if the given string is palindrome? " and it gives a lot of answers in different languages, but no answer that uses regular expressions. The answer to this question is that "it is impossible". More specifically, the interviewer is wondering if you paid attention in your computational theory class. In your computational theory class you learned about finite state machines. A finite state machine is composed of nodes and

How to check that a string is a palindrome using regular expressions?

Deadly 提交于 2019-11-26 00:53:52
问题 That was an interview question that I was unable to answer: How to check that a string is a palindrome using regular expressions? p.s. There is already a question \"How to check if the given string is palindrome?\" and it gives a lot of answers in different languages, but no answer that uses regular expressions. 回答1: The answer to this question is that "it is impossible". More specifically, the interviewer is wondering if you paid attention in your computational theory class. In your

How to check for palindrome using Python logic [closed]

守給你的承諾、 提交于 2019-11-26 00:37:41
问题 I\'m trying to check for a palindrome with Python. The code I have is very for -loop intensive. And it seems to me the biggest mistake people do when going from C to Python is trying to implement C logic using Python, which makes things run slowly, and it\'s just not making the most of the language. I see on this website. Search for \"C-style for\", that Python doesn\'t have C-style for loops. Might be outdated, but I interpret it to mean Python has its own methods for this. I\'ve tried