Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

(Previous Answer removed)

UPDATE:

Now that I understand the problem better, I see that my previous answer is no good. I think you need a new algorithm. What you have currently is getting into a combinatorial explosion. Try using a string difference algorithm against the reversed string. For example:

input: abca

reversed: acba

difference:

abc a
a cba

So you can now see that you need to insert one letter to make the string match the reversed string. String differences can be determined relatively efficiently using dynamic programming.

Here is another example:

input: tostotor

reversed: rototsot

difference:

t ostot or
 ro totso t

So three letters are needed to make them match.

UPDATE:

You can find more information on how to determine the differences between strings here: http://stackoverflow.com/questions/208094/how-to-find-difference-between-two-strings https://stackoverflow.com/questions/208094/how-to-find-difference-between-two-strings

(Previous Answer removed)

UPDATE:

Now that I understand the problem better, I see that my previous answer is no good. I think you need a new algorithm. What you have currently is getting into a combinatorial explosion. Try using a string difference algorithm against the reversed string. For example:

input: abca

reversed: acba

difference:

abc a
a cba

So you can now see that you need to insert one letter to make the string match the reversed string. String differences can be determined relatively efficiently using dynamic programming.

Here is another example:

input: tostotor

reversed: rototsot

difference:

t ostot or
 ro totso t

So three letters are needed to make them match.

UPDATE:

You can find more information on how to determine the differences between strings here: http://stackoverflow.com/questions/208094/how-to-find-difference-between-two-strings

(Previous Answer removed)

UPDATE:

Now that I understand the problem better, I see that my previous answer is no good. I think you need a new algorithm. What you have currently is getting into a combinatorial explosion. Try using a string difference algorithm against the reversed string. For example:

input: abca

reversed: acba

difference:

abc a
a cba

So you can now see that you need to insert one letter to make the string match the reversed string. String differences can be determined relatively efficiently using dynamic programming.

Here is another example:

input: tostotor

reversed: rototsot

difference:

t ostot or
 ro totso t

So three letters are needed to make them match.

UPDATE:

You can find more information on how to determine the differences between strings here: https://stackoverflow.com/questions/208094/how-to-find-difference-between-two-strings

added 191 characters in body
Source Link

(Previous Answer removed)

UPDATE:

Now that I understand the problem better, I see that my previous answer is no good. I think you need a new algorithm. What you have currently is getting into a combinatorial explosion. Try using a string difference algorithm against the reversed string. For example:

input: abca

reversed: acba

difference:

abc a
a cba

So you can now see that you need to insert one letter to make the string match the reversed string. String differences can be determined relatively efficiently using dynamic programming.

Here is another example:

input: tostotor

reversed: rototsot

difference:

t ostot or
 ro totso t

So three letters are needed to make them match.

UPDATE:

You can find more information on how to determine the differences between strings here: http://stackoverflow.com/questions/208094/how-to-find-difference-between-two-strings

(Previous Answer removed)

UPDATE:

Now that I understand the problem better, I see that my previous answer is no good. I think you need a new algorithm. What you have currently is getting into a combinatorial explosion. Try using a string difference algorithm against the reversed string. For example:

input: abca

reversed: acba

difference:

abc a
a cba

So you can now see that you need to insert one letter to make the string match the reversed string. String differences can be determined relatively efficiently using dynamic programming.

Here is another example:

input: tostotor

reversed: rototsot

difference:

t ostot or
 ro totso t

So three letters are needed to make them match.

(Previous Answer removed)

UPDATE:

Now that I understand the problem better, I see that my previous answer is no good. I think you need a new algorithm. What you have currently is getting into a combinatorial explosion. Try using a string difference algorithm against the reversed string. For example:

input: abca

reversed: acba

difference:

abc a
a cba

So you can now see that you need to insert one letter to make the string match the reversed string. String differences can be determined relatively efficiently using dynamic programming.

Here is another example:

input: tostotor

reversed: rototsot

difference:

t ostot or
 ro totso t

So three letters are needed to make them match.

UPDATE:

You can find more information on how to determine the differences between strings here: http://stackoverflow.com/questions/208094/how-to-find-difference-between-two-strings

Post Migrated Here from stackoverflow.com (revisions)
Source Link

(Previous Answer removed)

UPDATE:

Now that I understand the problem better, I see that my previous answer is no good. I think you need a new algorithm. What you have currently is getting into a combinatorial explosion. Try using a string difference algorithm against the reversed string. For example:

input: abca

reversed: acba

difference:

abc a
a cba

So you can now see that you need to insert one letter to make the string match the reversed string. String differences can be determined relatively efficiently using dynamic programming.

Here is another example:

input: tostotor

reversed: rototsot

difference:

t ostot or
 ro totso t

So three letters are needed to make them match.

lang-c

AltStyle によって変換されたページ (->オリジナル) /