Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

en/lc/648/ #3072

giscus[bot] bot announced in Announcements
Jun 7, 2024 · 1 comments · 2 replies
Discussion options

en/lc/648/

LeetCode solutions in any programming language

https://leetcode.doocs.org/en/lc/648/

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

Interested, why Array(26) chosen for the initialisation of the every layer of the trie?
(this.children = new Array<Trie>(26);)

I guess, usual hash-map {} will be better by the usage of space.
And also there will be no need to convert every next character into index with a .charCodeAt(0)

You must be logged in to vote
2 replies
Comment options

klever34 Jun 7, 2024
Collaborator

Well, yeah a hash map only stores the characters that are actually used, potentially saving space if the trie is sparse (i.e., not all 26 children are used at every node).

Comment options

Hello, based on my experience with solving LeetCode algorithm problems, for some programming languages such as Java and C++, allocating a static array is more efficient than using a hash table. Therefore, I tend to use a static array instead of a hash table.

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

AltStyle によって変換されたページ (->オリジナル) /