-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
en/lc/648/ #3072
-
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
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)
Beta Was this translation helpful? Give feedback.
All reactions
-
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).
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1