2013年12月6日

Max Points on a Line

摘要: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.思路:这道题的数据好像很弱,我只用了最普通的方法居然可以AC。对于每个点,求其他点到他连线的斜率,如果斜率相同,就表示在同一条直线上,用hash记录斜率和点的数目的关系。复杂度是O(n^2)的。最开始出错是因为没有考虑重复点的情况,加上这方面判断就AC了。代码: 1 int maxPoints(vector &points) { 2 int n = points.size(); ... 阅读全文

posted @ 2013-12-06 20:52 waruzhi 阅读(224) 评论(0) 推荐(0) 编辑

LRU Cache

摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the value if the key is not 阅读全文

posted @ 2013-12-06 19:42 waruzhi 阅读(226) 评论(0) 推荐(0) 编辑

导航