• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
上一页 1 2 3 4 5 6 7 8 9 10 ··· 21 下一页
2017年1月31日
Summary: Calculate average where sum exceed double limits
摘要: According to the highest vote in: http://stackoverflow.com/questions/1930454/what-is-a-good-solution-for-calculating-an-average-where-the-sum-of-all-v 阅读全文
posted @ 2017-01-31 01:38 neverlandly 阅读(284) 评论(0) 推荐(0)
2017年1月28日
Pocket Gem OA: Log Parser
摘要: 涉及到处理Date, 以及STDIN from a file 处理Date可以用SimpleDateFormat这个class static Date parseTime(String timeStr) { Date time = new Date(); DateFormat dft = new S 阅读全文
posted @ 2017-01-28 12:25 neverlandly 阅读(817) 评论(0) 推荐(0)
Pocket Gem OA: Path Finder
摘要: 题不难,主要是注意STDIN 阅读全文
posted @ 2017-01-28 12:19 neverlandly 阅读(1031) 评论(0) 推荐(0)
2017年1月24日
Leetcode: Sliding Window Median
摘要: 方法1:Time Complexity O(NK) 暂时只有两个Heap的做法,缺点:In this problem, it is necessary to be able remove elements that are not necessarily at the top of the heap 阅读全文
posted @ 2017-01-24 05:24 neverlandly 阅读(748) 评论(0) 推荐(0)
2017年1月23日
Leetcode: Number Complement
摘要: Better solution: Returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified int va 阅读全文
posted @ 2017-01-23 23:54 neverlandly 阅读(333) 评论(0) 推荐(0)
2017年1月20日
FB面经 Prepare: Even Tree
摘要: 我觉得题中应该再加上一个条件,就是guarantee是能够分割的,不然没法做. 如果总node总数是奇数的话, 怎么删都没法保证所有的子树是even number,所以这题的前提是node总数为偶数? 网上看到别人的很好的解法: 特别是用iterator.next()以后用iterator.remo 阅读全文
posted @ 2017-01-20 00:35 neverlandly 阅读(942) 评论(0) 推荐(0)
2017年1月16日
FB面经 Prepare: All Palindromic Substrings
摘要: Spread from center: Like LC 5: longest palindromic substring 阅读全文
posted @ 2017-01-16 13:55 neverlandly 阅读(511) 评论(0) 推荐(0)
FB面经 Prepare: Largest Island
摘要: Find largest island in a board 1 package fb; 2 3 public class LargestIsland { 4 public int findLargestIsland(int[][] board) { 5 if (board==null || board.length==0 || board[0].le... 阅读全文
posted @ 2017-01-16 11:03 neverlandly 阅读(429) 评论(0) 推荐(0)
FB面经 Prepare: Task Schedule
摘要: tasks has cooldown time, give an input task id array, output finish time input: AABCA A--ABCA output:7 1 package fb; 2 3 import java.util.*; 4 5 public class Scheduler { 6 7 pub... 阅读全文
posted @ 2017-01-16 01:07 neverlandly 阅读(1321) 评论(0) 推荐(0)
2017年1月11日
Leetcode Articles: Insert into a Cyclic Sorted List
摘要: Solution:Basically, you would have a loop that traverse the cyclic sorted list and find the point where you insert the value (Let’s assume the value b 阅读全文
posted @ 2017-01-11 00:40 neverlandly 阅读(1636) 评论(0) 推荐(0)
2017年1月9日
Summary: How to calculate PI? Based on Monte Carlo method
摘要: refer to: http://www.stealthcopter.com/blog/2009/09/python-calculating-pi-using-random-numbers/ During my undergraduate degree I wrote a program in fo 阅读全文
posted @ 2017-01-09 13:34 neverlandly 阅读(683) 评论(0) 推荐(0)
2017年1月7日
U家面试prepare: Serialize and Deserialize Tree With Uncertain Children Nodes
摘要: The method to serialize is like this: (1(2)(3(5)(6))(4(7))) if '(', right shift 1 position to the start of the number, use while loop to find the end 阅读全文
posted @ 2017-01-07 12:43 neverlandly 阅读(330) 评论(0) 推荐(0)
2016年12月24日
Leetcode: LFU Cache && Summary of various Sets: HashSet, TreeSet, LinkedHashSet
摘要: referred to: https://discuss.leetcode.com/topic/69137/java-o-1-accept-solution-using-hashmap-doublelinkedlist-and-linkedhashset Two HashMaps are used, 阅读全文
posted @ 2016-12-24 03:43 neverlandly 阅读(580) 评论(0) 推荐(0)
2016年12月23日
Leetcode: Poor Pigs
摘要: My binary encoding method gives a 8 for the first problem, however, there is a smarter method that generates a answer of 5, which can be found here: h 阅读全文
posted @ 2016-12-23 11:37 neverlandly 阅读(1112) 评论(0) 推荐(0)
Leetcode: Validate IP Address
摘要: Be careful, split() will not include trailing empty strings in the result array The string "boo:and:foo", for example, split(":")的结果是 {“boo”, "and", " 阅读全文
posted @ 2016-12-23 08:44 neverlandly 阅读(1092) 评论(0) 推荐(0)
Leetcode: Encode String with Shortest Length && G面经
摘要: DP: Initially I think of 1D DP, dp[i] stands for the shortest string of first i characters, then: dp[i] = minLen{dp[k] + encode(substring(k+1, i))} th 阅读全文
posted @ 2016-12-23 06:25 neverlandly 阅读(2173) 评论(0) 推荐(0)
Leetcode: Concatenated Words
摘要: Scan through array and DP: We iterate through each word and see if it can be formed by using other words. The subproblem is Word Break I. But it is a 阅读全文
posted @ 2016-12-23 01:40 neverlandly 阅读(1340) 评论(0) 推荐(0)
2016年12月22日
Leetcode: Convex Polygon
摘要: https://discuss.leetcode.com/topic/70706/beyond-my-knowledge-java-solution-with-in-line-explanation https://discuss.leetcode.com/topic/70664/c-7-line- 阅读全文
posted @ 2016-12-22 13:14 neverlandly 阅读(966) 评论(0) 推荐(0)
Leetcode: Unique Substrings in Wraparound String
摘要: 这道题我一开始发现了数学规律: length of consecutive chars vs number of different substring “a” -> 1 = 1 "ab" -> 3 = 1+2 "abc" -> 6 = 1+2+3 "abcd" -> 10 = 1+2+3+4 于是 阅读全文
posted @ 2016-12-22 11:05 neverlandly 阅读(632) 评论(0) 推荐(0)
Leetcode: Count The Repetitions
摘要: 目前只想出了Brute Force做法(1165ms), 看到有<20ms的做法,未深究: 阅读全文
posted @ 2016-12-22 07:24 neverlandly 阅读(670) 评论(0) 推荐(0)
Leetcode: Optimal Account Balancing
只有注册用户登录后才能阅读该文。 阅读全文
posted @ 2016-12-22 05:53 neverlandly 阅读(1705) 评论(0) 推荐(0)
2016年12月21日
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 阅读(606) 评论(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 阅读(756) 评论(0) 推荐(0)
2016年12月20日
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 阅读(1541) 评论(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 阅读(973) 评论(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 阅读(843) 评论(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 阅读(686) 评论(0) 推荐(0)
2016年12月19日
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 阅读(488) 评论(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 阅读(467) 评论(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 阅读(954) 评论(0) 推荐(0)
Leetcode: Hamming Distance
摘要: Solution 1: Solution 2: 阅读全文
posted @ 2016-12-19 09:17 neverlandly 阅读(239) 评论(0) 推荐(0)
Leetcode: Valid Word Square
摘要: 这题看起来简单但是其实很容易写错 本来想j 不从0开始,而是从 i+1开始检查,可以节省时间,但是一些为Null的情况会使讨论很复杂 比如 阅读全文
posted @ 2016-12-19 08:37 neverlandly 阅读(295) 评论(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 阅读(1142) 评论(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 阅读(888) 评论(0) 推荐(0)
2016年12月18日
Leetcode: Design Phone Directory
摘要: my HashSet+ ArrayList, 删除的时候把要删的index与末尾对调。get()其实不需要random, 因为anyone is ok HashSet+ Queue网上vote最高的solution, 阅读全文
posted @ 2016-12-18 13:37 neverlandly 阅读(343) 评论(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 阅读(530) 评论(0) 推荐(0)
Leetcode: Range Addition
摘要: Time Complexity: O(N+K), Space: O(1) 阅读全文
posted @ 2016-12-18 11:49 neverlandly 阅读(335) 评论(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 阅读(300) 评论(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 阅读(724) 评论(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 阅读(501) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 10 ··· 21 下一页
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3