今天小弟问了我一个问题,问题如下:
Given a list of strings & string M28K, where M28K represents a string which starts
from M, ends with K and has 28chars in between . Find if M28K is unique in the
list of strings or not?
我想出了以下算法来找到问题的解决方案:
对于每个字符串:
find string length(L)
if(L==30) then
if(str[0]=='M' && str[L-1]=='K') then
verify rest of 28 characters are matching or not
就时间复杂度而言,该解决方案似乎效率不高。谁能给出更好的算法来解决这个问题?