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. H5页面测试总结

    前言 在最近几个项目中,小编接触了较多关于H5页面的测试,H5页面的测试除了业务逻辑功能测试外,其他部分的测试方法基本是可以通用的,在此对H5页面的一些通用测试方法进行总结分享给大家. H5页面介绍 ...

  2. (十七)线程,connect的第五个参数

    采用多线程,将需要处理的后台数据放入子线程,为了能够跨线程调用,一种方法是使用类似线程锁对线程进行保护,另外一种方法使用Qt的信号槽机制.Qt的信号槽机制采用connect函数进行连接,connect ...

  3. 初学node node开发环境搭建 node模块化 commonJS原理

    由于Node.js平台是在后端运行JavaScript代码,所以,必须首先在本机安装Node环境. 学习node,首先要装node,和它的包管理工具,这两个都是傻瓜式安装,百度一下就安装了. 安装完之 ...

  4. js面向对象学习笔记

    1.函数的定义方式 第一种定义方式 function fn1() { alert("fn1"); } alert(fn) 函数就是一个特殊的对象,是一个Function类的实例,其 ...

  5. SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xce in position 0: invalid continuatio

    点击  文档>>设置文件编码>>Unicode>>Unicode(UTF-8)

  6. pydub音频处理库的使用

    pydub音频处理库的使用 在使用pydub这个模块之前应确保你的libav或者FFmpeg Mac上安装libav或FFmpeg brew install libav --with-libvorbi ...

  7. AT3912 Antennas on Tree

    AT3912 Antennas on Tree %%zzt 只能考虑性质了. 把最后选择的k个点的连通块求出来,连通块内部的点表示都是互异的 连通块外部的点只能形成若干条链,并且这k个点的每一个最多与 ...

  8. JS判断开始时间不能大于检查结束时间

    //用来检验检查开始时间不能大于检查结束时间 function checkDate(date){ var startDate = $("#jcrwModel_rwfqsj").va ...

  9. 图解golang内存分配机制 (转)

    一般程序的内存分配 在讲Golang的内存分配之前,让我们先来看看一般程序的内存分布情况: 以上是程序内存的逻辑分类情况. 我们再来看看一般程序的内存的真实(真实逻辑)图: Go的内存分配核心思想 G ...

  10. mybatis 操作其他数据库的数据表

    配置文件里面配置的数据库只是默认数据库,并不是只能操作默认数据库.(被自己蠢死了,唉) 1. 注解方式 使用BaseMapper方式操作数据表时,在表对应的实体类上的 @table 注解描述表名时加上 ...