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. 1、Netty 实战入门详解

    一.Netty 简介 Netty 是基于 Java NIO 的异步事件驱动的网络应用框架,使用 Netty 可以快速开发网络应用,Netty 提供了高层次的抽象来简化 TCP 和 UDP 服务器的编程 ...

  2. select拼接

    //if (Data1[i].MisFunId == 1) //{ // if (Data1[i].Flag == true) // { // var t = Data1[i].MisFunId; / ...

  3. (转)SQLServer_十步优化SQL Server中的数据访问 三

    原文地址:http://tech.it168.com/a2009/1125/814/000000814758_all.shtml 第六步:应用高级索引 实施计算列并在这些列上创建索引 你可能曾经写过从 ...

  4. c++界面库方案

    最近的开发需要向java以及c++方向转向:看了些java和c++的东西 最近研究了下,最后觉得使用ogre+mygui来实现c++界面,这样用比较方便: 当前ogre,mygui都可以实现界面,可以 ...

  5. 对Spring Ioc的理解

    1. 新建一个maven项目,工程目录如下 2. 添加接口MessageService及其实现类MessageServiceImpl MessageService.java package com.p ...

  6. Spring 回滚事务@Transactional

    @Transactional   spring 事务注解 默认遇到throw new RuntimeException("...");会回滚 需要捕获的throw new Exce ...

  7. Android开发 解决EditText与NestedScrollView 滚动冲突问题

    问题简述 在将EditText套进NestedScrollView的情况下,EditText输入了多行内容后,无法触摸滚动到第一行 问题原因 在将EditText套进NestedScrollView的 ...

  8. 练习: bs4 简单爬取 + matplotlib 折线图显示 (关键词,职位数量、起薪)

    要看一种技术在本地的流行程度,最简单的就是找招聘网站按关键词搜索. 比如今天查到的职位数量是vue 1296个,react 1204个,angular 721个.国际上比较流行的是react,本地市场 ...

  9. 4Linux环境变量、Vim、Shell脚本

    环境变量 命令在Linux中的执行分为4个步骤: 1.以路径的形式来执行 2.命令的别名形式来执行,alias 新命令=“原始命令”,新命令与原始命令互不冲突,可以同时使用,重启失效,修改/etc/p ...

  10. 如何自学Java开发

    对于这个话题,已经不止N次在线上或线下听到了.从这个话题被太多的人提问及回答,我们可以肯定地说,Java这个已经有近15年头的计算机编程语言是有着及其广阔的应用领域和独特而短期无法替代的优势.我们姑且 ...