摘要:
The idea is to add a set to the hashMap to remember all the locations of a duplicated number.
阅读全文
posted @ 2016-11-29 02:44
neverlandly
阅读(525)
推荐(0)
摘要:
最先想到是用double LinkedList+Map, 没必要,arraylist+map就够了;另外取random的方法还有,rand.nextInt(int n) returns an integer in the range [0, n) java.util.Random rand = ne
阅读全文
posted @ 2016-11-29 01:27
neverlandly
阅读(533)
推荐(0)
摘要:
Heap: you need to know the row number and column number of that element(so we can create a tuple class here) Binary Search方法:(12/28仔细看了之后觉得没必要深究,有时间再去
阅读全文
posted @ 2016-11-28 13:02
neverlandly
阅读(426)
推荐(0)
摘要:
DP 解法: the key to solve DP problem is to think about how to create overlap, how to re-solve subproblems(怎么制造复用) Bottom up dp: Better Solution(Bottom-u
阅读全文
posted @ 2016-11-28 11:40
neverlandly
阅读(328)
推荐(0)
摘要:
DP solution is O(N^2), better way is greedy Now for explanation, we take example series:2,1,4,5,6,3,3,4,8,4 First we check if the series is starting a
阅读全文
posted @ 2016-11-28 10:26
neverlandly
阅读(533)
推荐(0)
摘要:
Clarification of the problem: https://discuss.leetcode.com/topic/68252/clarification-on-the-problem-description-problem-description-need-to-be-updated
阅读全文
posted @ 2016-11-28 06:43
neverlandly
阅读(838)
推荐(0)
摘要:
Binary Search Here "My" means the number which is given for you to guess not the number you put into guess(int num).
阅读全文
posted @ 2016-11-28 05:33
neverlandly
阅读(401)
推荐(0)
摘要:
Better Solution: O(KlogK), 转自https://discuss.leetcode.com/topic/50885/simple-java-o-klogk-solution-with-explanation Some observations: For every numbe
阅读全文
posted @ 2016-11-28 04:55
neverlandly
阅读(586)
推荐(0)
摘要:
ab % k = (a%k)(b%k)%kSince the power here is an array, we'd better handle it digit by digit.One observation:a^1234567 % k = (a^1234560 % k) * (a^7 % k
阅读全文
posted @ 2016-11-28 01:48
neverlandly
阅读(398)
推荐(0)
摘要:
DP Solution similar to Longest Increasing Subsequence: 我的解法:用一个arraylist存以某一个element结尾的最长sequence 别人的好方法,大体思路一样,只是不存arraylist, 而用一个preIndex数组存以某一个elem
阅读全文
posted @ 2016-11-27 01:24
neverlandly
阅读(429)
推荐(0)
摘要:
参考:https://discuss.leetcode.com/topic/49238/math-solution-java-solution The basic idea is to use the property of Bézout's identity and check if z is a
阅读全文
posted @ 2016-11-27 00:10
neverlandly
阅读(655)
推荐(0)
摘要:
转自https://discuss.leetcode.com/topic/49771/java-simple-easy-understand-solution-with-explanation/2,注意里面对于减法的讲解 have been confused about bit manipulati
阅读全文
posted @ 2016-11-26 11:53
neverlandly
阅读(349)
推荐(0)
摘要:
Reference: https://discuss.leetcode.com/topic/48875/accepted-c-codes-with-explanation-and-references/2 The naive solution is brute-force, which is O((
阅读全文
posted @ 2016-11-26 08:01
neverlandly
阅读(644)
推荐(0)
摘要:
Analysis: A number of unique digits is a number which is a combination of unrepeated digits. So, we can calculate the total number. for number with n
阅读全文
posted @ 2016-11-26 04:20
neverlandly
阅读(340)
推荐(0)
摘要:
注意需要maintain一个time stamp, 每次postTweet时++。还有要注意unfollow的时候,不能unfollow自己 关于PriorityQueue还看到这一种写法,挺简单的: 1 Set<Integer> users = userMap.get(userId).follow
阅读全文
posted @ 2016-11-26 01:58
neverlandly
阅读(435)
推荐(0)
摘要:
1-9 : count:9 * len:1 10-99: count:90 * len:2 100-999: count:900 * len:3 1000-9999: count: 9000 * len:4 maintain a count, len, start
阅读全文
posted @ 2016-11-25 06:51
neverlandly
阅读(303)
推荐(0)
摘要:
DP 解法, Time Complexity: O(N^2) sort based on width or height, anyone is ok. After the sorting, for each envelope, those envelopes which can fit into t
阅读全文
posted @ 2016-11-25 05:36
neverlandly
阅读(596)
推荐(0)
摘要:
TreeMap 解法: Use TreeMap to easily find the lower and higher keys, the key is the start of the interval.Merge the lower and higher intervals when neces
阅读全文
posted @ 2016-11-25 02:06
neverlandly
阅读(420)
推荐(0)
摘要:
我的binary Search 解法:无需变成long 别人三种方法总结:
阅读全文
posted @ 2016-11-24 12:50
neverlandly
阅读(330)
推荐(0)
摘要:
用HashMap Follow Up 1: 用two pointer解,可以省存成HashMap Follow Up 2: 用在长的数组里面binary Search可解 Follow Up 3: What if elements of nums2 are stored on disk, and t
阅读全文
posted @ 2016-11-24 11:52
neverlandly
阅读(285)
推荐(0)
摘要:
Use two hash sets Time complexity: O(n) 注意Set<Integer> set = new HashSet<>(); 第二个泛型可以不写出 Iterator iter = set2.iterator(); for (int i=0; i<res.length;
阅读全文
posted @ 2016-11-24 10:34
neverlandly
阅读(319)
推荐(0)
摘要:
很像majority element III, 但是那道题有O(k) extra space的限制,这里没有。有任意extra space, 同时知道elem range情况下,bucket sort最节省时间 语法上注意第5行,建立一个ArrayList的array,后面没有泛型generic L
阅读全文
posted @ 2016-11-24 06:51
neverlandly
阅读(315)
推荐(0)
摘要:
Two Pointers 解法, 注意大小写
阅读全文
posted @ 2016-11-24 05:20
neverlandly
阅读(273)
推荐(0)
摘要:
O(N^2)解法: DP dp[i] represent the maximum product of breaking up integer i O(N)解法: the best factor is 3. we keep breaking n into 3's until n gets small
阅读全文
posted @ 2016-11-24 04:57
neverlandly
阅读(356)
推荐(0)
摘要:
非常精巧地使用stack。push all the nestedList into the stack from back to front,so when we pop the stack, it returns the very first element 执行hasNext()的时候,如果pe
阅读全文
posted @ 2016-11-24 01:29
neverlandly
阅读(424)
推荐(0)
摘要:
After the API changes 注意没有append(0, s.charAt(i)), 是sb.insert(0, charAt(i));
阅读全文
posted @ 2016-11-23 12:20
neverlandly
阅读(303)
推荐(0)
摘要:
it's easy to find that power of 4 numbers have those 3 common features. First,greater than 0. Second,only have one '1' bit in their binary notation,so
阅读全文
posted @ 2016-11-23 11:48
neverlandly
阅读(245)
推荐(0)
摘要:
https://discuss.leetcode.com/topic/39834/step-by-step-tackling-of-the-problem rob(root) which will return the maximum amount of money that we can rob
阅读全文
posted @ 2016-11-23 11:17
neverlandly
阅读(326)
推荐(0)
posted @ 2016-11-23 07:36
neverlandly
阅读(359)
推荐(0)
摘要:
Naive Solution: Time: O(n^2*k) with n the total number of words in the "words" array and k the average length of each word: check each combination see
阅读全文
posted @ 2016-11-23 06:29
neverlandly
阅读(362)
推荐(0)
摘要:
4th line may cross with 1st line, and so on: 5th with 2nd, ...etc 5th line may cross with 1st line, and so on: 6th with 2nd, ...etc 6th line also may
阅读全文
posted @ 2016-11-23 03:51
neverlandly
阅读(381)
推荐(0)
摘要:
Naive Solution: use DP, Time O(N^2), Space O(N) dp[i] represents the length of longest increasing subsequence till i including element i in nums array
阅读全文
posted @ 2016-11-23 01:42
neverlandly
阅读(363)
推荐(0)
摘要:
我的想法:假设给定的点事ListNode oneNode, 设置ListNode dummy = new ListNode(-1); dummy.next = oneNode 然后扫描一次找到环里最后一个点,断链:ListNode end.next = null; 然后就开始扫描,删点 然后再扫描一
阅读全文
posted @ 2016-10-19 00:49
neverlandly
阅读(544)
推荐(0)
摘要:
设计一个shuffle card 用了java. Random Class 1 package Random; 2 import java.util.*; 3 4 public class Solution { 5 static int cardNum = 10; 6 public int[] sh
阅读全文
posted @ 2016-02-17 04:50
neverlandly
阅读(612)
推荐(0)
摘要:
The definition of integer average is the highest smaller integer if average is floating point number. Also the condition if that they can not use any
阅读全文
posted @ 2016-02-16 11:56
neverlandly
阅读(398)
推荐(0)
摘要:
Given an array which has n integers,it has both positive and negative integers.Now you need sort this array in a special way.After that,the negative i
阅读全文
posted @ 2016-02-16 07:40
neverlandly
阅读(383)
推荐(0)
摘要:
给定一个char array, 这个array是一个句子,然后给定一个字母,把这个array里面带有这个字母开头的单次删掉,操作是要求in place. 检测 array[i]==' ' && i<array.length-1 && array[i+1]==target,这种情况,设置j从i+1开始
阅读全文
posted @ 2016-02-16 04:15
neverlandly
阅读(324)
推荐(0)
摘要:
You have two every large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of
阅读全文
posted @ 2016-02-08 23:45
neverlandly
阅读(422)
推荐(0)
摘要:
refer to Recursion https://leetcode.com/discuss/84702/share-my-solution and Iteration https://leetcode.com/discuss/84706/share-solution-java-greedy-st
阅读全文
posted @ 2016-02-08 12:29
neverlandly
阅读(4097)
推荐(0)
摘要:
You are given a binary tree (not necessarily BST) in which each node contains a value. Design an algorithm to print all paths which sum up to that val
阅读全文
posted @ 2016-02-04 12:02
neverlandly
阅读(618)
推荐(0)