• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅

随笔分类 -  Leetcode

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 32 下一页
Leetcode: Optimal Account Balancing

只有注册用户登录后才能阅读该文。
posted @ 2016-12-22 05:53 neverlandly 阅读(1705) 评论(0) 推荐(0)
Leetcode: Matchsticks to Square && Grammar: reverse an primative array

摘要:DFS, my solution is to fill each edge of the square one by one. DFS to construct the 1st, then 2nd, then 3rd, then 4th. For each edge I scan all the m 阅读全文
posted @ 2016-12-21 07:31 neverlandly 阅读(603) 评论(0) 推荐(0)
Leetcode: Serialize and Deserialize BST

摘要:So the first question is: what is the difference between this and #297? This here is BST, however, in #297, it's BT. "The encoded string should be as 阅读全文
posted @ 2016-12-21 04:44 neverlandly 阅读(752) 评论(0) 推荐(0)
Leetcode: Circular Array Loop

摘要:注意The loop must be "forward" or "backward'. 所以这就是为什么[-2, 1, -1, -2, -2]是false的原因 Just think it as finding a loop in Linkedlist, except that loops with 阅读全文
posted @ 2016-12-20 11:39 neverlandly 阅读(1539) 评论(0) 推荐(0)
Leetcode: Sequence Reconstruction

摘要:Topological Sort: This problem is to determine if there's one, and only one sequence to sort a DAG. The method is to check if the queue's size is alwa 阅读全文
posted @ 2016-12-20 07:15 neverlandly 阅读(968) 评论(0) 推荐(0)
Leetcode: Ternary Expression Parser

摘要:My First Solution: Use Stack and String operation, from the back of the string, find the first '?', push the right to stack. Depends on whether the ch 阅读全文
posted @ 2016-12-20 05:11 neverlandly 阅读(840) 评论(0) 推荐(0)
Leetcode: Word Squares && Summary: Another Important Implementation of Trie(Retrieve all the words with a given Prefix)

摘要:Backtracking + Trie: referred to https://discuss.leetcode.com/topic/63516/explained-my-java-solution-using-trie-126ms-16-16 A better approach is to ch 阅读全文
posted @ 2016-12-20 01:38 neverlandly 阅读(680) 评论(0) 推荐(0)
Leetcode: Ones and Zeroes

摘要:This is a 0/1 backpacking problem The problem can be interpreted as: What's the max number of str can we pick from strs with limitation of m "0"s and  阅读全文
posted @ 2016-12-19 13:32 neverlandly 阅读(485) 评论(0) 推荐(0)
Leetcode: Heaters

摘要:Binary Search My solution: Be careful in my binary search function, l, r may go out of the range of the array Solution with the highest vote: 阅读全文
posted @ 2016-12-19 13:09 neverlandly 阅读(464) 评论(0) 推荐(0)
Leetcode: Total Hamming Distance

摘要:Example: 0 0 0 0 0 1 0 0 1 1 1 0 0 0 1 0 Total Hamming Distance = (3*1) + (2*2) + (2*2) + (4*0) = 11 so the idea is count the number of 1 and 0 on eac 阅读全文
posted @ 2016-12-19 11:03 neverlandly 阅读(952) 评论(0) 推荐(0)
Leetcode: Hamming Distance

摘要:Solution 1: Solution 2: 阅读全文
posted @ 2016-12-19 09:17 neverlandly 阅读(234) 评论(0) 推荐(0)
Leetcode: Valid Word Square

摘要:这题看起来简单但是其实很容易写错 本来想j 不从0开始,而是从 i+1开始检查,可以节省时间,但是一些为Null的情况会使讨论很复杂 比如 阅读全文
posted @ 2016-12-19 08:37 neverlandly 阅读(291) 评论(0) 推荐(0)
Leetcode: Sentence Screen Fitting

摘要:先来一个brute force, 类似Text Adjustment 但是在稍微大一点的case就TLE了,比如: ["a","b","e"] 20000 20000, 花了465ms 所以想想怎么节约时间, 提示是可以DP的,想想怎么复用,refer to: https://discuss.lee 阅读全文
posted @ 2016-12-19 07:16 neverlandly 阅读(1135) 评论(0) 推荐(0)
Leetcode: Minimum Unique Word Abbreviation

摘要:Refer to https://discuss.leetcode.com/topic/61799/java-bit-mask-dfs-with-pruning bit mask refer to http://bookshadow.com/weblog/2016/10/02/leetcode-mi 阅读全文
posted @ 2016-12-19 04:47 neverlandly 阅读(885) 评论(0) 推荐(0)
Leetcode: Design Phone Directory

摘要:my HashSet+ ArrayList, 删除的时候把要删的index与末尾对调。get()其实不需要random, 因为anyone is ok HashSet+ Queue网上vote最高的solution, 阅读全文
posted @ 2016-12-18 13:37 neverlandly 阅读(340) 评论(0) 推荐(0)
Leetcode: Valid Word Abbreviation

摘要:Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation. A string such as "word" contains only the following valid abbreviations: ["word",... 阅读全文
posted @ 2016-12-18 12:49 neverlandly 阅读(529) 评论(0) 推荐(0)
Leetcode: Range Addition

摘要:Time Complexity: O(N+K), Space: O(1) 阅读全文
posted @ 2016-12-18 11:49 neverlandly 阅读(332) 评论(0) 推荐(0)
Leetcode: Find Leaves of Binary Tree

摘要:Better Solution: https://discuss.leetcode.com/topic/49194/10-lines-simple-java-solution-using-recursion-with-explanation/2 For this question we need t 阅读全文
posted @ 2016-12-18 09:12 neverlandly 阅读(296) 评论(0) 推荐(0)
Leetcode: Design Hit Counter

摘要:Use Queue Better Solution: can solve follow up, refer to https://discuss.leetcode.com/topic/48758/super-easy-design-o-1-hit-o-s-gethits-no-fancy-data- 阅读全文
posted @ 2016-12-18 07:56 neverlandly 阅读(722) 评论(0) 推荐(0)
Leetcode: Bomb Enemy

摘要:Walk through the matrix. At the start of each non-wall-streak (row-wise or column-wise), count the number of hits in that streak and remember it. For 阅读全文
posted @ 2016-12-18 06:52 neverlandly 阅读(499) 评论(0) 推荐(0)

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 32 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3