Every unique item in the input appears exactly 3 times.
Examples:
[1, 1, 1]=>true[1, 2, 3]=>false
Consider a cache-like data structure with operations such as get and put, where items are inserted and retrieved by key.
MyCache mc = new MyCache(4)
mc.get('a') => None
mc.put('a', 'alligator')
mc.put('b', 'baby')
mc.put('c', 'candy')
mc.put('d', 'door')
mc.put('e', 'elephant')
mc.get('a') => ?
这题的核心是统计输入中每个元素出现的次数,并判断是否所有不同元素都恰好出现 3 次。对于数组示例,可以先用哈希表记录频次,再遍历检查每个值是否等于 3;如果题目还包含类似缓存的操作场景,则需要结合哈希表和双向链表 / 有序结构来支持高效的 <code>get</code> 与 <code>put</code>,重点是理解题目要求的状态维护方式,而不是单纯做一次性遍历。
正文完