Skip to content

Faster string query #35

Description

@pan199612

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions