zoukankan      html  css  js  c++  java
  • [leetcode]432. All O`one Data Structure全O(1)数据结构

    Implement a data structure supporting the following operations:

    1. 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.
    2. 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.
    3. GetMaxKey() - Returns one of the keys with maximal value. If no element exists, return an empty string "".
    4. 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.

    题意:

    设计一个类似hash map的计数器,但要提供最大值对应键值、最小值对应键值的功能。

    Solution1:

    code

  • 相关阅读:
    JQ选择器
    设计模式
    招银网络面试
    斗鱼面经
    招银科技面经
    用户访问网站基本流程
    shell的条件判断
    crontab -e 和/etc/crontab的区别
    秘钥对登录配置
    CentOS6 x86_64最小化安装优化脚本
  • 原文地址:https://www.cnblogs.com/liuliu5151/p/10772149.html
Copyright © 2011-2022 走看看