2015年4月5日
摘要: 解答从这里来比较麻烦的字符串细节实现题。需要解决以下几个问题:首先要能判断多少个word组成一行: 这里统计读入的所有words的总长curLen,并需要计算空格的长度。假如已经读入words[0:i]。当curLen + i L时,一行结束。知道一行的所有n个words,以及总长curLen之后... 阅读全文
posted @ 2015-04-05 11:10 Seth_L 阅读(153) 评论(0) 推荐(0) 编辑
摘要: /* * Check if two trees are the same */public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p == null && q... 阅读全文
posted @ 2015-04-05 10:13 Seth_L 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 见过在onsite的居多Given a list of houses and the cost of painting each house, the houses can be painted in three colors RED, GREEN and BLUE, two nei... 阅读全文
posted @ 2015-04-05 09:22 Seth_L 阅读(147) 评论(0) 推荐(0) 编辑
  2015年4月4日
摘要: // O(n^2) time and O(1) space// Given a center, either one letter or two letter, // Find longest palindromeprivate String expandCenter(String ... 阅读全文
posted @ 2015-04-04 13:58 Seth_L 阅读(98) 评论(0) 推荐(0) 编辑
摘要: public void shuffle(int[] A) { if (A == null || A.length == 0) return; for (int i = 0; i < A.length-1; ++i) { int random = Math.r... 阅读全文
posted @ 2015-04-04 13:28 Seth_L 阅读(125) 评论(0) 推荐(0) 编辑
  2015年4月3日
摘要: Say I’m given a 2d array where all the numbers in the array are in increasing order from left to right and top to bottom.What is the best way ... 阅读全文
posted @ 2015-04-03 14:33 Seth_L 阅读(105) 评论(0) 推荐(0) 编辑
摘要: /**Solution 1, using recursion. Construct a list of numbers by maintaining what you have now and what is left. Every level you take one elemen... 阅读全文
posted @ 2015-04-03 10:39 Seth_L 阅读(132) 评论(0) 推荐(0) 编辑
摘要: /**O(n)的解法,从左到右遍历。**/public class Solution { public int[] searchRange(int[] A, int target) { if(A.length == 0) { return n... 阅读全文
posted @ 2015-04-03 10:01 Seth_L 阅读(160) 评论(0) 推荐(0) 编辑
  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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(0) 编辑
摘要: /** * Definition for undirected graph. * class UndirectedGraphNode { * int label; * List neighbors; * UndirectedGraphNode(int x) {... 阅读全文
posted @ 2015-03-31 14:45 Seth_L 阅读(91) 评论(0) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(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) 推荐(0) 编辑