随笔分类 -  FB

摘要:Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operators a 阅读全文
posted @ 2017-12-28 05:11 apanda009 阅读(204) 评论(0) 推荐(0)
摘要:Use buckets to record the last position of digit 0 ~ 9 in this num. Loop through the num array from left to right. For each position, we check whether 阅读全文
posted @ 2017-12-20 13:04 apanda009 阅读(138) 评论(0) 推荐(0)
摘要:The sample input is very confusing when time t has mixed meaning of beginning of time t for start and end of time t for end We can increase all end ti 阅读全文
posted @ 2017-12-20 12:53 apanda009 阅读(171) 评论(0) 推荐(0)
摘要:注意这道题:Must be exactly one distance apart. Not the same. 另外FB面经有一道比较狠的这个题的变形: 这题就是one edit distance的变形题,难点在于给的Iterator,事先不知道两个file的长度,也不允许用extra space( 阅读全文
posted @ 2017-12-20 12:08 apanda009 阅读(161) 评论(0) 推荐(0)
摘要:小心这里是index triplets, 不是nums[i]数组元素的triplets, 所以3Sum那道题里面的跳过条件不用了 因为不关心每个index具体是什么,只关心个数,所以可以排序 阅读全文
posted @ 2017-12-20 10:36 apanda009 阅读(146) 评论(0) 推荐(0)
摘要:Time Complexity will be O(n) because the "start" and "end" points will only move from left to right once. 阅读全文
posted @ 2017-12-20 06:24 apanda009 阅读(137) 评论(0) 推荐(0)
摘要:我又想到了另一个idea,使用那个assumption可以达到O(1) 复杂度:首先判断isUp or not,仅以isUp为例, 假设A[x] 是最高点,则有:A[x] - A[i] = x - i. A[x] - A[j] = j - x由此可以解出 x = 1/ 2 * (A[j] - A[i 阅读全文
posted @ 2017-12-20 02:49 apanda009 阅读(166) 评论(0) 推荐(0)
摘要:A->B->C->D->E | V M | V N 有right和down的linkedlist,要求更新linkedlist变成A->M->N->B->C->D->E,注意M可以还有right,B也可以有down,其实就是递归输出。然后我做了一会才做出,之前有个大神的面经里发过,但我没仔细看很后悔。我昨晚发现这tmd不是inorder traversal么 // Class to ... 阅读全文
posted @ 2017-12-13 01:05 apanda009 阅读(262) 评论(0) 推荐(0)
摘要:写了一行,面试官打断我,让我再说一下思路,我又说了一下准备定义一个array,n+1的size,第一个存0,保存到当前值的所有之前numbers的和,然后比如query(0,3),就能用preSum[4]-preSum[0];他表示不懂...我又举了3个例子...面试官表示ok,但你不要写代码,先写 阅读全文
posted @ 2017-12-13 00:12 apanda009 阅读(171) 评论(0) 推荐(0)
摘要:The idea is to use two arrays len[n] and cnt[n] to record the maximum length of Increasing Subsequence and the coresponding number of these sequence w 阅读全文
posted @ 2017-12-13 00:00 apanda009 阅读(178) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings.第二遍做法:时间复杂度应该是O(m*n),m表示字符串的最大长度,n表示字符串的个数,空间复杂度应该是O(m),即字符串的长度 public class Solution { public String longest... 阅读全文
posted @ 2017-12-03 10:27 apanda009 阅读(160) 评论(0) 推荐(0)
摘要:Solution 1: Reservior sampling: (wiki introduction) Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items 阅读全文
posted @ 2017-11-28 01:36 apanda009 阅读(176) 评论(0) 推荐(0)
摘要:Strobogrammatic Number II give us all the strings with length n, then we can call it to get strings with length between low.length() and high.length() 阅读全文
posted @ 2017-11-27 13:04 apanda009 阅读(135) 评论(0) 推荐(0)
摘要:参考http://segmentfault.com/a/1190000003787462 找出所有的可能,必然是深度优先搜索。但是每轮搜索如何建立临时的字符串呢?因为数是“对称”的,我们插入一个字母就知道对应位置的另一个字母是什么,所以我们可以从中间插入来建立这个临时的字符串。这样每次从中间插入两个 阅读全文
posted @ 2017-11-27 12:56 apanda009 阅读(180) 评论(0) 推荐(0)
摘要:A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to determine if a number is strobogrammatic. The number is represented as ... 阅读全文
posted @ 2017-11-27 12:48 apanda009 阅读(143) 评论(0) 推荐(0)
摘要:The general solution would be to check each char in turn and report the first char that makes the string a non number. There are some exceptions to wa 阅读全文
posted @ 2017-11-13 06:17 apanda009 阅读(180) 评论(0) 推荐(0)
摘要:Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are c 阅读全文
posted @ 2017-11-13 00:55 apanda009 阅读(171) 评论(0) 推荐(0)
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc 阅读全文
posted @ 2017-11-07 05:06 apanda009 阅读(495) 评论(0) 推荐(0)
摘要:/*Given a string and dictionary of words, break the string into minimum number of words from the dictionary. Ex: {"jumped", "over", "some", "thing”, " 阅读全文
posted @ 2017-11-01 10:07 apanda009 阅读(549) 评论(0) 推荐(0)
摘要:字符串匹配的问题应该最先想到dp, 主要还是说一下动态规划的方法。跟Regular Expression Matching一样,还是维护一个假设我们维护一个布尔数组res[i],代表s的前i个字符和p的前j个字符是否匹配(这里因为每次i的结果只依赖于j-1的结果,所以不需要二维数组,只需要一个一维数 阅读全文
posted @ 2017-08-19 20:40 apanda009 阅读(157) 评论(0) 推荐(0)