• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
2016年12月7日
Leetcode: Number of Boomerangs
摘要: Solution: Use HashTable, Time: O(N^2), Space: O(N) 我的:注意14行是有value个重复distance,表示有value个点,他们跟指定点距离都是distance,需要选取2个做permutation, 所以是value * (value-1) 别 阅读全文
posted @ 2016-12-07 13:51 neverlandly 阅读(496) 评论(0) 推荐(0)
Leetcode: Arranging Coins
摘要: count is the # of level, sum is the accumulated coins Better Solution: Binary Search, 因为怕溢出,所以(1+m)m/2表示成了line6那种样子. 用m去估计最后返回的row 阅读全文
posted @ 2016-12-07 13:44 neverlandly 阅读(291) 评论(0) 推荐(0)
Leetcode: Path Sum III
摘要: Add the prefix sum to the hashMap, and check along path if hashMap.contains(pathSum+cur.val-target); My Solution 一个更简洁的solution: using HashMap to stor 阅读全文
posted @ 2016-12-07 12:17 neverlandly 阅读(612) 评论(0) 推荐(0)
Leetcode: All O`one Data Structure
摘要: Solution: O(1) time complexity 解题思路主要参考了网友ivancjw的帖子,数据结构参考了https://discuss.leetcode.com/topic/65634/java-ac-all-strict-o-1-not-average-o-1-easy-to-re 阅读全文
posted @ 2016-12-07 09:09 neverlandly 阅读(1428) 评论(0) 推荐(0)
Leetcode: Find Right Interval
摘要: Solution 1: TreeMap, Time complexity: O(NlogN) 像这种在一个集合里面寻找有没有比某个数小的数,一般要么treeMap要么treeSet。Interval的题经常需要用treeMap, Data Stream as Disjoint Intervals 就 阅读全文
posted @ 2016-12-07 04:53 neverlandly 阅读(449) 评论(0) 推荐(0)
Leetcode: Non-overlapping Intervals
摘要: Actually, the problem is the same as "Given a collection of intervals, find the maximum number of intervals that are non-overlapping." (the classic Gr 阅读全文
posted @ 2016-12-07 01:28 neverlandly 阅读(765) 评论(0) 推荐(0)
Leetcode: Number of Segments in a String
摘要: 用split() 不用API, better solution, O(N) time O(1) space 阅读全文
posted @ 2016-12-07 00:36 neverlandly 阅读(417) 评论(0) 推荐(0)
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3