skyline
1
I have an array eg:
AAAZZZ
…
ZZZCCC
…
I need to work out AAACCC by finding a common connection (if there is one)
In this case it’s: AAAZZZ ZZZCCC (ie the ZZZ is the connection)
So what’s the best way to find out that ZZZ is the 3 characters that are shared?
system
2
I would do something like this
assume
str1 = ‘AAAZZZ’;
str2 = ‘ZZZCCC’;
-
move pointer to the first char in str1
-
then take a substring of that char plus the next 2 chars.
-
search str2 for the existence of the substring in 2)
-
move the pointer in 1) to the next char
-
repeat steps 2-5 until a common string is found or you get to the 2nd last char in 1)