Design a trie with insert, search, and startsWith. search only succeeds for complete inserted words, while startsWith succeeds for any stored prefix path.
Every operation should update or query the same trie instance across the operation sequence.
A trie is a tree-like data structure used to store strings efficiently.
Store shared prefixes one character at a time. Distinguish between a path that exists and a complete word that ends at that path.
Examples
Input: operations = ["Trie","insert","search","search","startsWith","insert","search"], words = ["","apple","apple","app","app","app","app"] Output: [null,null,true,false,true,null,true]
Input: operations = ["Trie","insert","startsWith","search"], words = ["","hello","he","hell"] Output: [null,null,true,false]
Constraints
- 1 <= operations.length <= 20,000
- 1 <= words[i].length <= 200
- words[i] consists of lowercase English letters.