You are given several logs that each log contains a unique id and timestamp. Timestamp is a string that has the following format: Year:Month:Day:Hour:Minute:Second, for example, 2017:01:01:23:59:59. All domains are zero-padded decimal numbers.

Design a log storage system to implement the following functions:

void Put(int id, string timestamp): Given a log's unique id and timestamp, store the log in your storage system.

int[] Retrieve(String start, String end, String granularity): Return the id of logs whose timestamps are within the range from start to end. Start and end all have the same format as timestamp. However, granularity means the time level for consideration. For example, start = "2017:01:01:23:59:59", end = "2017:01:02:23:59:59", granularity = "Day", it means that we need to find the logs within the range from Jan. 1st 2017 to Jan. 2nd 2017.

Example 1:

put(1, "2017:01:01:23:59:59");
put(2, "2017:01:01:22:59:59");
put(3, "2016:01:01:00:00:00");
retrieve("2016:01:01:01:01:01","2017:01:01:23:00:00","Year"); // return [1,2,3], because you need to return all logs within 2016 and 2017.
retrieve("2016:01:01:01:01:01","2017:01:01:23:00:00","Hour"); // return [1,2], because you need to return all logs start from 2016:01:01:01 to 2017:01:01:23, where log 3 is left outside the range.

Note:

  1. There will be at most 300 operations of Put or Retrieve.
  2. Year ranges from [2000,2017]. Hour ranges from [00,23].
  3. Output for Retrieve has no order required.
 class LogSystem {
List<String []> logs;
List<String> units = Arrays.asList("Year", "Month", "Day", "Hour", "Minute", "Second");
int [] indices = new int[]{,,,,,}; public LogSystem() {
logs = new LinkedList<String []>();
} public void put(int id, String timestamp) {
logs.add(new String[]{Integer.toString(id), timestamp});
} public List<Integer> retrieve(String s, String e, String gra) {
List<Integer> res = new ArrayList<Integer>();
int ind = indices[units.indexOf(gra)]; String sSub = s.substring(, ind);
String eSub = e.substring(, ind); for(String [] log : logs){
String sub = log[].substring(, ind);
if(sub.compareTo(sSub)>= && sub.compareTo(eSub)<=){
res.add(Integer.valueOf(log[]));
}
}
return res;
}
} /**
* Your LogSystem object will be instantiated and called as such:
* LogSystem obj = new LogSystem();
* obj.put(id,timestamp);
* List<Integer> param_2 = obj.retrieve(s,e,gra);
*/

Design Log Storage System的更多相关文章

  1. [LeetCode] Design Log Storage System 设计日志存储系统

    You are given several logs that each log contains a unique id and timestamp. Timestamp is a string t ...

  2. LeetCode Design Log Storage System

    原题链接在这里:https://leetcode.com/problems/design-log-storage-system/description/ 题目: You are given sever ...

  3. [leetcode-635-Design Log Storage System]

    You are given several logs that each log contains a unique id and timestamp. Timestamp is a string t ...

  4. Bigtable: A Distributed Storage System for Structured Data

    https://static.googleusercontent.com/media/research.google.com/en//archive/bigtable-osdi06.pdf Abstr ...

  5. Storage System and File System Courses

    I researched a lot about storage system classes given at good universities this year. This had two r ...

  6. 1.1 Introduction中 Kafka as a Storage System官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Kafka as a Storage System kafka作为一个存储系统 An ...

  7. Blockstack: A Global Naming and Storage System Secured by Blockchains

    作者:Muneeb Ali, Jude Nelson, Ryan Shea, and Michael Freedman Blockstack Labs and Princeton University ...

  8. f4: Facebook’s Warm BLOB Storage System——Erasure Code

    Facebook在OSDI 2014上发表论文f4: Facebook's Warm BLOB Storage System,这个系统主要目的就是降低存储成本,在容忍磁盘,主机,机架,数据中心的同时提 ...

  9. Bigtable:A Distributed Storage System for Strctured Data

    2006 年10 月Google 发布三架马车之一的<Bigtable:A Distributed Storage System for Strctured Data>论文之后,Power ...

随机推荐

  1. closest(expr|object|element)

    closest(expr|object|element) 概述 jQuery 1.3新增.从元素本身开始,逐级向上级元素匹配,并返回最先匹配的元素..大理石平台生产厂 closest会首先检查当前元素 ...

  2. 小米 oj 马走日 (bfs 或 双向bfs)

     马走日 序号:#56难度:困难时间限制:1500ms内存限制:10M 描述 在中国象棋中,马只能走日字型.现在给出一个由 N*M 个格子组成的中国象棋棋盘( 有(N+1)*(M+1)个交叉点可以落子 ...

  3. 决策树算法的Python实现—基于金融场景实操

    决策树是最经常使用的数据挖掘算法,本次分享jacky带你深入浅出,走进决策树的世界 基本概念 决策树(Decision Tree) 它通过对训练样本的学习,并建立分类规则,然后依据分类规则,对新样本数 ...

  4. Codeforces 55D. Beautiful numbers(数位DP,离散化)

    Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...

  5. 线程的join()方法

    官网描述 join public final void join() throws InterruptedException Waits for this thread to die. An invo ...

  6. LVS集群之DR模式

    今天来讲LVS-DR模式集群实现负载均衡的搭建方法 环境 主机名 IP   系统 角色 dir DIP:192.168.199.9 VIP:192.168.199.8 rhel7.4 集群服务器 no ...

  7. 事件处理机制与Handler消息传递机制

    一.基于监听的事件处理机制 基于监听的时间处理机制模型: 事件监听机制中由事件源,事件,事件监听器三类对象组成 处理流程如下: Step 1:为某个事件源(组件)设置一个监听器,用于监听用户操作 St ...

  8. Python list 遇到的问题

    1.list“+” 运算 <list += > diff. <ndarray +=> list1 += list2是追加,而不是加法运算 list1 = [0,0,0] lis ...

  9. 炉石兄弟 修复图腾师问题 by大神beebee102, 还有阴燃电鳗

    修复图腾师问题   beebee102 修复了先摇图腾再下图腾师的问题,另外加了阴燃电鳗的sim卡.在兄弟策略的模拟程序中测试了没问题,真机没有试过,麻烦吧友测试了回复一下.链接: [有效] http ...

  10. Mac下mysql服务端密码重置及环境配置

    一 停止mysql服务 关闭MySQL服务的操作: 苹果->系统偏好设置->最下边点MySQL 在弹出页面中 关闭mysql服务(点击stop mysql server) 二 进入终端,命 ...