注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
设计个结构,存key,time,value
要insert(key,time,value)和get(key),get(key,time)
get(key)的时候,要是一个key有好几个time,那么返回过去最近的那个
get(key,time) 就是返回过去离time最近的那个。
看过面经,我就说用treemap。。。他说你用bst,写一个呗。。。code半天一推bug,跪了
这是全是bug的代码,可能设计的也不好。大家随便看看吧
class Solution {
12, 'loc2'
10, 'loc1'
15, 'loc3'
10 = 'loc1'
14 = 'loc2'
public static void main(String[] args) {
MyTree mt= node.val;
return get(time,node.right);
} else {
if(node.left==null) {
if(pre==null) return not found;
return pre.val;
}
return get(time,node.left);
}
}
}
}
|