[LeetCode] All O`one Data Structure 全O的数据结构
Posted Grandyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] All O`one Data Structure 全O的数据结构相关的知识,希望对你有一定的参考价值。
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.
以上是关于[LeetCode] All O`one Data Structure 全O的数据结构的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode] 1277. Count Square Submatrices with All Ones
LeetCode Playground & Binary Tree Traversal All In One
Linux command line editor nano All In One