The Most Efficient Algorithm to Find First Prefix-Match From a Sorted String Array?

前端 未结 8 725
春和景丽
春和景丽 2021-01-31 00:27

Input:

1) A huge sorted array of string SA;

2) A prefix string P;

Output:

The index of the first string matching the input prefix if any. If ther

8条回答
  •  梦毁少年i
    2021-01-31 00:32

    My current solution in mind is, instead of to find the "prefix", try to find a "virtual prefix".

    For example, prefix is “abd", try to find a virtual-prefix “abc(255)". (255) just represents the max char number. After locating the "abc(255)". The next word should be the first word matching "abd" if any.

提交回复
热议问题