1

I want to compare two arrays of numbers(no duplications), to find all sub arrays with length of 2 and above that appear in both of the original arrays.

I am looking for most efficient way to implements this.

4

1 回答 1

1

This reminds me of Longest Common Substring Problem Read the wiki page, it has good description of problem, good references and even pseudocode. There are 2 ways to solve it: Suffix tree and Dynamic Programming. Suffix tree appears to be a more efficient solution, but it might be more complex, depending on your implementation.

If you are not familiar with Dynamic Programming, read up on it. The only difference between your problem and Longest Common Substring is that you have an array of unique integers, whereas here they had repeating characters in the string.

You might use that to your advantage, but I don't think you would get major efficiency improvement.

于 2013-10-27T18:34:42.230 回答