• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
2016年11月30日
Leetcode: Random Pick Index
摘要: Three types of answer: Map Solution, O(N) memory, O(N) init, O(1) pick. Like @dettier's Reservoir Sampling. O(1) init, O(1) memory, but O(N) to pick. 阅读全文
posted @ 2016-11-30 12:23 neverlandly 阅读(410) 评论(0) 推荐(0)
Leetcode: Sum of Left Leaves
摘要: Recursion: 是不是left子数完全由bottom往上第二层决定,如果是left子树且是叶子节点,那么就是left leaves, parent得告诉child是不是在left子树 BFS: 阅读全文
posted @ 2016-11-30 11:45 neverlandly 阅读(370) 评论(0) 推荐(0)
Leetcode: Is Subsequence
摘要: Basic Solution: DP, O(mn) time, O(m) space, m is the size of s, n is the size of t Greedy Solution: O(n) time, O(1) space Follow Up: The best solution 阅读全文
posted @ 2016-11-30 11:09 neverlandly 阅读(1189) 评论(0) 推荐(0)
Leetcode: Elimination Game
摘要: refer to https://discuss.leetcode.com/topic/59293/java-easiest-solution-o-logn-with-explanation Time Complexity: O(log n) update and record head in ea 阅读全文
posted @ 2016-11-30 06:52 neverlandly 阅读(360) 评论(0) 推荐(0)
Leetcode: Find the Difference
摘要: O(N)time, O(1) space 阅读全文
posted @ 2016-11-30 05:40 neverlandly 阅读(251) 评论(0) 推荐(0)
Leetcode: Longest Absolute File Path
摘要: Time Complexity: O(N) The depth of the directory/file is calculated by counting how many "\t"s are there.The time complexity is O(n) because each subs 阅读全文
posted @ 2016-11-30 05:19 neverlandly 阅读(362) 评论(0) 推荐(0)
Leetcode: Mini Parser
摘要: 有括号这种一般要用stack, stack top 就是当前着眼的那一个NestedInteger, 可以对其添加新的元素。 注意47行判断很关键,顺带处理了 "[]," 括号后面是逗号的情况 阅读全文
posted @ 2016-11-30 02:28 neverlandly 阅读(379) 评论(0) 推荐(0)
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3