A new way (trie) to solve the problem


  • 0
    Z

    It seems most solutions are based on hash table and double linked list. My solution is based on trie.
    It can still be seen as O(1), just the const factor being on the large side. Even for the hash table solution, for each operation, hashing cost is still liner to the length of the key.
    We definitely need store the min/max child information in each node and update those information when doing inc/dec. When doing getmin/getmax, we can easily build the string following the path of min/max.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.