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. PHP mysqli_num_rows() 函数

    <?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localhost","root& ...

  2. 微信小程序开发入门教程(三)---小程序云开发支付功能

    支付(shoukuan)功能真的很重要!由于我还没有商户号,以下代码未实际验证 1.服务端 进入云开发,新建云函数pay(应该也可以在开发者工具编写后上传) 编写后端代码index.js这里用到第三方 ...

  3. 【线性代数】2-2:消元(Eliminate)

    title: [线性代数]2-2:消元(Eliminate) toc: true categories: Mathematic Linear Algebra date: 2017-08-31 16:1 ...

  4. elastic search&logstash&kibana 学习历程(四)kibana安装部署和使用

    kibana在linux上的部署安装 运行环境是centos7 基于jdk8 下载安装包:wget https://artifacts.elastic.co/downloads/kibana/kiba ...

  5. js中的DOM对象和jQuery对象的比较

    1. 二者的不同之处: 通过jQuery获取的元素是一个数组, 数组中包含着原生JS中的DOM对象. 例如, 针对下面的一个div结构: <div id="Box">& ...

  6. java.util.Date和java.sql.Date的区别和相互转化 (转)

    java.util.Date和java.sql.Date的区别及应用   java.util.Date 就是在除了SQL语句的情况下面使用 java.sql.Date 是针对SQL语句使用的,它只包含 ...

  7. buff/cache占用过高的问题

    工作记录 > /proc/sys/vm/drop_caches 默认是0,不清除缓冲区缓存和页面缓存 可用值 0 到 3 值越高系统上的程序会跑起来越慢 free -m 蛋疼的是这只是一次性的, ...

  8. FutureTask用法及解析

    1 FutureTask概念 FutureTask一个可取消的异步计算,FutureTask 实现了Future的基本方法,提空 start cancel 操作,可以查询计算是否已经完成,并且可以获取 ...

  9. Flutter打开第三方应用

    在flutter中打开第三方应用可以使用url_launcher插件 打开https://pub.dartlang.org/,然后搜索url_launcher,然后点击进入该插件界面 大家在insta ...

  10. android Activity,Fragment,Application内存状态监听及等级

    @Override public void onTrimMemory(int level) { super.onTrimMemory(level); switch (level){ case TRIM ...