string_score icon indicating copy to clipboard operation
string_score copied to clipboard

Faster string query

Open pan199612 opened this issue 6 years ago • 0 comments

Hello, I think you can use a hash table to speed up the query.

  1. Create a hash table of words, with key values as characters, and values as positions of characters。 Word: Hello User Input: eao image

2)Find the character entered by the user: ‘e’, Find by hash table, find the index greater than 0 (you can use binary search)。 The word index is at position 1.

  1. Find the character entered by the user: ‘a’, Find by hash table, find index greater than 1 (you can use binary search) 'A' not found, index does not move

4)Find the character entered by the user: ‘o’, Find by hash table, find the index greater than 0 (you can use binary search)。 The word index is at position 4.

I'm not familiar with js, I can't implement it with code, I'm really sorry.

pan199612 avatar Feb 01 '20 00:02 pan199612