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

[leetcode]432. All O`one Data Structure全O(1)数据结构的更多相关文章

  1. [LeetCode] All O`one Data Structure 全O(1)的数据结构

    Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...

  2. [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  3. LeetCode 170. Two Sum III - Data structure design (两数之和之三 - 数据结构设计)$

    Design and implement a TwoSum class. It should support the following operations: add and find. add - ...

  4. [LeetCode] 170. Two Sum III - Data structure design 两数之和之三 - 数据结构设计

    Design and implement a TwoSum class. It should support the following operations:add and find. add - ...

  5. ✡ leetcode 170. Two Sum III - Data structure design 设计two sum模式 --------- java

    Design and implement a TwoSum class. It should support the following operations: add and find. add - ...

  6. leetcode Add and Search Word - Data structure design

    我要在这里装个逼啦 class WordDictionary(object): def __init__(self): """ initialize your data ...

  7. leetcode[170]Two Sum III - Data structure design

    Design and implement a TwoSum class. It should support the following operations: add and find. add - ...

  8. [leetcode]170. Two Sum III - Data structure design两数之和III - 数据结构设计

    Design and implement a TwoSum class. It should support the following operations: add and find. add - ...

  9. LeetCode——Add and Search Word - Data structure design

    Description: Design a data structure that supports the following two operations: void addWord(word) ...

随机推荐

  1. LDAP & Implentation

    LDAP: LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP.它是基于X.500标准的,但是简单多了并且可以根据需 ...

  2. C语言排序算法学习笔记——选择类排序

    选择排序:每一趟(例如第i趟)在后面n-i+1(i=1,2,3,……,n-1)个待排序元素中选取关键字最小的元素,作为有序子序列的第i个元素,直到n-1趟做完,待排序元素只剩下1个,就不用再选了. 简 ...

  3. python pdfkit html转pdf响应式轮子 django例

    pip install pdfkit 本例用django做的请求,换成对应框架即可 此方法可将html页面转成pdf下载 #!/usr/bin/env python # coding:utf-8 im ...

  4. IDE 热部署配置

    从eclipse切换到IDE,遇到应用不能热部署问题,解决如下 1.tomcat 中server配置下面三点需要注意 2.tomcat的deployment 中 需要选择war exploded而不是 ...

  5. 批量查杀该死的VBscript “svchost.exe” 脚本挂马

    今天写代码突然发现HTML文件最后多了一段VBscript代码: <SCRIPT Language=VBScript><!-- DropFileName = "svchos ...

  6. PG数据库中用户权限

    每当在数据库中创建一个对象,所有者可以分配它访问权限.所有者通常是执行创建语句的用户.对于大多数类型的对象,初始状态是,只有所有者(或超级用户)可以修改或删除对象.为了让其他角色或用户使用它,特权或权 ...

  7. [UNITY 5.4 UGUI] 模态对话框

    1.建立两个画布 a.背景界面 b.置顶界面(添加一个 panel 控件) 2.修改置顶界面中 panel ,添加属性 [Canvas Group] 3.根据界面设计情况修改透明度,色彩,图片

  8. win10以管理员身份运行cmd方法

    win10以管理员身份运行cmd方法 win8win10以管理员身份运行cmd方法1.直接到 C:\Windows\System32 下面找cmd.exe 右键以管理员方式打开就可以了 2.按WIN+ ...

  9. MPC学习笔记1:基于状态空间模型的预测控制(2)

    基于估计的无约束预测控制 1.引言 基本上这两个部分都是在线性理论的框架下,利用状态空间法来建模.求解控制律.状态空间模型在理论分析上具有很强的优越性,但实际应用中能直接准确且经济地获取系统状态并不容 ...

  10. PeopleSoft查看所有translate value

    下面sql可以列出PS中所有translate value SELECT FIELDNAME, FIELDVALUE, EFFDT, EFF_STATUS, XLATLONGNAME, XLATSHO ...