美文网首页
432. All O`one Data Structure

432. All O`one Data Structure

作者: matrxyz | 来源:发表于2018-01-16 08:35 被阅读0次

    Implement a data structure supporting the following operations:
    Inc(Key) - Inserts a new key with value 1. Or increments an existing key by 1. Key is guaranteed to be a non-empty string.
    Dec(Key) - If Key's value is 1, remove it from the data structure. Otherwise decrements an existing key by 1. If the key does not exist, this function does nothing. Key is guaranteed to be a non-empty string.
    GetMaxKey() - Returns one of the keys with maximal value. If no element exists, return an empty string "".
    GetMinKey() - Returns one of the keys with minimal value. If no element exists, return an empty string "".

    Challenge: Perform all these in O(1) time complexity.

    Solution:

    思路:

    https://leetcode.com/problems/all-oone-data-structure/discuss/91416

    Time Complexity: O(N) Space Complexity: O(N)

    Solution Code:

    
    

    相关文章

      网友评论

          本文标题:432. All O`one Data Structure

          本文链接:https://www.haomeiwen.com/subject/oiwjoxtx.html