码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-10-30 00:37:08      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:ons   minimal   tin   cti   win   turn   element   time   return   

 

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.

 

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

标签:ons   minimal   tin   cti   win   turn   element   time   return   

原文地址:http://www.cnblogs.com/grandyang/p/6012229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!