摘要:
参考了这个总结,非常详细:http://segmentfault.com/a/1190000003817671 最好方法: 映射找环法 复杂度 时间 O(N) 空间 O(1) 思路 假设数组中没有重复,那我们可以做到这么一点,就是将数组的下标和1到n每一个数一对一的映射起来。比如数组是213,则映射 阅读全文
摘要:
Push all gates into queue first. Then for each gate update its neighbor cells who is empty and push them to the queue. Repeating above steps until the 阅读全文
摘要:
第二遍做法: 双指针压缩法:O(N), 空间:O(1) 实际上就是将所有的非0数向前尽可能的压缩,最后把没压缩的那部分全置0就行了。比如103040,先压缩成134,剩余的3为全置为0。过程中需要一个指针记录压缩到的位置。 Q:如果要把所有的0放在前面而不是后面呢?A:同样的解题思路,但是是从后向前 阅读全文
摘要:
My thinking is: use a double cache: long cache, when no number is cached, cache = Long.MIN_VALUE. When i call next(), it will firstly check if there's 阅读全文
摘要:
网上看到更好的方法:https://leetcode.com/discuss/77805/java-5ms-short-code-with-explanations The idea is to compare root's value with p's value if root is not n 阅读全文
摘要:
Best Solution: O(N) This solution also works for K vectors Use a queue to store the iterators in different vectors. Every time we call next(), we pop 阅读全文
摘要:
Given an unsorted array nums, reorder it in-place such that nums[0] = nums[2] = nums[i - 1]如果i是偶数,nums[i] nums[i - 1], 则交换以后肯定有nums[i] =nums[i-1])) {... 阅读全文
摘要:
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, ... 阅读全文
摘要:
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c... 阅读全文
摘要:
最佳做法:O(N)time, O(1)space The first pass is to pick out the candidate. If candidate knows i, then switch candidate. The second pass is to check whether 阅读全文
摘要:
Career Cup 150 Pg 442 Think of Convert(19,323,984) = Process(19) + "million" + Process(323) + "thousand" + Process(984) + "" The Process is a process 阅读全文