2015年4月2日
摘要:
print all permutation of strings From Herepublic static void permutation(String str) { permutation("", str); }private static void permutat...
阅读全文
posted @ 2015-04-02 04:23
Seth_L
阅读(102)
推荐(0)
编辑
摘要:
public class Solution { public int[] twoSum(int[] numbers, int target) { HashMap num = new HashMap(); for(int i = 0; i array...
阅读全文
posted @ 2015-04-02 04:13
Seth_L
阅读(149)
推荐(0)
编辑
摘要:
Example:WordDistanceFinder finder = new WordDistanceFinder(Arrays.asList(“the”, “quick”, “brown”, “fox”, “quick”));assert(finder.distance(“fox...
阅读全文
posted @ 2015-04-02 04:05
Seth_L
阅读(474)
推荐(0)
编辑
2015年4月1日
摘要:
From Here For each node, 4 conditions: 1. Node only (因为本题中的节点可能是负值!) 2. L-sub + Node 3. R-sub + Node 4. L-sub + Node + R-sub (in here the max ...
阅读全文
posted @ 2015-04-01 13:37
Seth_L
阅读(116)
推荐(0)
编辑
摘要:
懒得自己写了。。代码这里来的:点击总体来讲就是先按照x来sort,x一样sort y, 然后比较前面的y和后面的xpublic ArrayList merge(ArrayList intervals) { ArrayList res = new ArrayList(); ...
阅读全文
posted @ 2015-04-01 13:29
Seth_L
阅读(84)
推荐(0)
编辑
摘要:
public class Solution { public ListNode mergeKLists(List lists) { if(lists == null || lists.size() == 0) { return null; ...
阅读全文
posted @ 2015-04-01 13:13
Seth_L
阅读(228)
推荐(0)
编辑
摘要:
From Here Solution: Remember that a line can be represented by y=kx+d, if p1 and p2 are in same line, then y1=x1k+d, y2=kx2+d, so y2-y1=k...
阅读全文
posted @ 2015-04-01 12:28
Seth_L
阅读(169)
推荐(0)
编辑
摘要:
From Here public static String FindAndReplace(String GivenString, String Pattern, String ReplaceString) { int j = 0; ...
阅读全文
posted @ 2015-04-01 12:07
Seth_L
阅读(110)
推荐(0)
编辑
2015年3月31日
摘要:
From Here Assume we have a binary tree below: _30_ / \ 10 20 / / \ 50 45 35Using pre-order traversal, the algorithm ...
阅读全文
posted @ 2015-03-31 23:12
Seth_L
阅读(105)
推荐(0)
编辑
摘要:
Given an array of numbers, nums, return an array of numbers products, where products[i] is the product of all nums[j], j != i. Input : [1...
阅读全文
posted @ 2015-03-31 23:09
Seth_L
阅读(88)
推荐(0)
编辑
摘要:
search for a target from a rotated sorted array non-recursion version from herepublic int search(int[] A, int target) { if(A==null || A.l...
阅读全文
posted @ 2015-03-31 22:56
Seth_L
阅读(128)
推荐(0)
编辑
摘要:
From Here /** * Given two nodes of a tree, * method should return the deepest common ancestor of those nodes. * * A ...
阅读全文
posted @ 2015-03-31 16:02
Seth_L
阅读(193)
推荐(0)
编辑
摘要:
/**This is for finding k nearest neighbor from the original pointusing a MAX heap, each time if the dist is less than the MAX we put it into t...
阅读全文
posted @ 2015-03-31 15:37
Seth_L
阅读(190)
推荐(0)
编辑
摘要:
From Here Changed it a littlepublic ArrayList> valid2(int[] A) { ArrayList> result = new ArrayList>(); Arrays.sort(A); fo...
阅读全文
posted @ 2015-03-31 15:26
Seth_L
阅读(109)
推荐(0)
编辑
摘要:
Just a BS(bulls**t) algorithm, nothing specialint binaryS (int[] array, int key, int min, int max) { if (max key) { return binaryS(...
阅读全文
posted @ 2015-03-31 15:09
Seth_L
阅读(116)
推荐(0)
编辑
摘要:
From Here Given a large network of computers, each keeping log files of visited urls, find the top ten most visited URLs.Ans: we will just mim...
阅读全文
posted @ 2015-03-31 14:56
Seth_L
阅读(146)
推荐(0)
编辑
摘要:
/** * Definition for undirected graph. * class UndirectedGraphNode { * int label; * List neighbors; * UndirectedGraphNode(int x) {...
阅读全文
posted @ 2015-03-31 14:45
Seth_L
阅读(91)
推荐(0)
编辑
摘要:
Given a binary tree, return the mirror of it. Very easy. RecursionTreeNode mirror(TreeNode root) { if (root == NULL) return NULL; else {...
阅读全文
posted @ 2015-03-31 14:25
Seth_L
阅读(128)
推荐(0)
编辑
摘要:
From Here 数学找规律public String getPermutation(int n, int k) { if(n nums = new ArrayList(); //initialize factorial for(int i=2;i=0) ...
阅读全文
posted @ 2015-03-31 14:22
Seth_L
阅读(91)
推荐(0)
编辑
摘要:
据说linkedin会考。。。没啥难的倒是public class Solution { public List> combinationSum2(int[] num, int target) { Arrays.sort(num); List> re...
阅读全文
posted @ 2015-03-31 14:12
Seth_L
阅读(111)
推荐(0)
编辑
摘要:
Implement a (Java) Iterable object that iterates lines one by one from a text file.. /** A reference to a file. */public class TextFile implem...
阅读全文
posted @ 2015-03-31 13:50
Seth_L
阅读(611)
推荐(0)
编辑
摘要:
From Here Given two (dictionary) words as Strings, determine if they are isomorphic.Two words are called isomorphic if the letters in one word...
阅读全文
posted @ 2015-03-31 13:42
Seth_L
阅读(138)
推荐(0)
编辑
摘要:
From HereLinkedin 的一道题目Keep track of the current remain factor to be decomposed, LargestFactor is the largest possible factor to decompose (s...
阅读全文
posted @ 2015-03-31 11:32
Seth_L
阅读(160)
推荐(0)
编辑
摘要:
Application layer shortening uses (original url => tiny url)expand url (tiny url => original url)Data Storage (hashtable tiny url’s hash code ...
阅读全文
posted @ 2015-03-31 10:28
Seth_L
阅读(237)
推荐(0)
编辑
摘要:
Code From Here (g4g)/**1) Initialize leftsum as 02) Get the total sum of the array as sum3) Iterate through the array and for each index i, d...
阅读全文
posted @ 2015-03-31 04:02
Seth_L
阅读(175)
推荐(0)
编辑
摘要:
print intersection of two sorted array 思路from g4g: 1) Use two index variables i and j, initial values i = 0, j = 0 2) If arr1[i] is smaller th...
阅读全文
posted @ 2015-03-31 03:48
Seth_L
阅读(133)
推荐(0)
编辑
摘要:
原帖地址:http://www.mitbbs.com/article_t/JobHunting/32909075.html 自己加了一点注释public static Iterable mergeKSortedIterators(List> Iters){ Queue ...
阅读全文
posted @ 2015-03-31 03:12
Seth_L
阅读(119)
推荐(0)
编辑
摘要:
From Here 这是一个带有upperbound的semaphore。public class BoundedSemaphore { private int signals = 0; private int bound = 0; public BoundedSemaph...
阅读全文
posted @ 2015-03-31 02:22
Seth_L
阅读(136)
推荐(0)
编辑
摘要:
implement Stack, getMin() is always O(1)class MinStack { LinkedList main = new LinkedList(); LinkedList min = new LinkedList(); publi...
阅读全文
posted @ 2015-03-31 01:18
Seth_L
阅读(103)
推荐(0)
编辑
摘要:
From here//thread safe singleton. static makes it guarantee that it only gets created at the first timepublic class Singleton { public final...
阅读全文
posted @ 2015-03-31 00:34
Seth_L
阅读(92)
推荐(0)
编辑
摘要:
dynamic programming 的一道题。curMax是包括当前元素的subarray的max, gloMax是当前元素之前的整个array的maxpublic class Solution { public int maxSubArray(int[] A) { ...
阅读全文
posted @ 2015-03-31 00:25
Seth_L
阅读(111)
推荐(0)
编辑
摘要:
又一个Linkedin面试过的public class Solution { public double pow(double x, int n) { int sign = 1; if(n < 0) { n = -n; ...
阅读全文
posted @ 2015-03-31 00:01
Seth_L
阅读(96)
推荐(0)
编辑