Design Log Storage System
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:
- There will be at most 300 operations of Put or Retrieve.
- Year ranges from [2000,2017]. Hour ranges from [00,23].
- 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的更多相关文章
- [LeetCode] Design Log Storage System 设计日志存储系统
You are given several logs that each log contains a unique id and timestamp. Timestamp is a string t ...
- LeetCode Design Log Storage System
原题链接在这里:https://leetcode.com/problems/design-log-storage-system/description/ 题目: You are given sever ...
- [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 ...
- Bigtable: A Distributed Storage System for Structured Data
https://static.googleusercontent.com/media/research.google.com/en//archive/bigtable-osdi06.pdf Abstr ...
- Storage System and File System Courses
I researched a lot about storage system classes given at good universities this year. This had two r ...
- 1.1 Introduction中 Kafka as a Storage System官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Kafka as a Storage System kafka作为一个存储系统 An ...
- Blockstack: A Global Naming and Storage System Secured by Blockchains
作者:Muneeb Ali, Jude Nelson, Ryan Shea, and Michael Freedman Blockstack Labs and Princeton University ...
- f4: Facebook’s Warm BLOB Storage System——Erasure Code
Facebook在OSDI 2014上发表论文f4: Facebook's Warm BLOB Storage System,这个系统主要目的就是降低存储成本,在容忍磁盘,主机,机架,数据中心的同时提 ...
- Bigtable:A Distributed Storage System for Strctured Data
2006 年10 月Google 发布三架马车之一的<Bigtable:A Distributed Storage System for Strctured Data>论文之后,Power ...
随机推荐
- import org.apache.ibatis.annotations.Param 报错
说明缺少依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus ...
- 11.17 模拟赛&&day-2
/* 后天就要复赛了啊啊啊啊啊. 可能是因为我是一个比较念旧的人吧. 讲真 还真是有点不舍. 转眼间一年的时间就过去了. 2015.12-2016.11. OI的一年. NOIP gryz RP++. ...
- Ubuntu安装配置mongodb
一:安装 -->官方教程 第一步: sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5 ...
- JQuery动画之滑入滑出动画
1. 滑入动画(类似于商店的卷帘门) $(selector).slideDown(speed, 回调函数); 解释: 此语句实现的功能为, 在XX时间内, 下拉动画, 显现元素. 当 slideDow ...
- Zookeeper系列(十一)zookeeper的Leader选举详解(核心之一)
作者:leesf 掌控之中,才会成功:掌控之外,注定失败. 出处:http://www.cnblogs.com/leesf456/p/6107600.html尊重原创,奇文共欣赏: 一.前言 前 ...
- vuejs2项目开发实战视频教程
0.课程大纲 一.点餐系统(移动) 1.0.课件 1.1.项目初始化_首页顶部 1.2.首页列表_底部导航 1.3.商家顶部_商家优惠信息弹层 1.4.商品主体_类别菜单 1.5.购物车操作_商品信息 ...
- python 操作excel openpyxl
1 安装 pip install openpyxl 如果装不上,请指定安装源来安装 pip install -i https://pypi.douban.com/simple openpyxl 如果e ...
- curl 使用笔记
一.使用案例 curl -H "cookie:userName=shangyy" www.baidu.com 二.使用 1.从Netscape的网页服务器上获得该网站的主页: cu ...
- jQuery常用Method-API
目的:对web页面(HTML/JSP/XML)中的任何标签,属性,内容进行增删改查 (1)DOM简述与分类 (A)DOM是一种W3C官方标准规则,可访问任何标签语言的页面(HTML/JSP/XML) ...
- php的时区修改
Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to ...