• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
09 2014 档案
Microsoft Interview第一轮

摘要:上来随意交谈了一小会儿,开了点小玩笑,chat了一些关于他们recruter行程的话题,缓和了一下气氛。进入正题,问了做的research的方向,我说是DLT,然后大概给他讲解了一下具体是什么, 跟平行计算很像,举了一个例子:矩阵乘法如何划分使并行效率最高。他表示理解。然后他又问我有没有过end t... 阅读全文
posted @ 2014-09-27 07:07 neverlandly 阅读(531) 评论(0) 推荐(1)
面经:Bloomberg Internship第一轮

摘要:上来先问了一个系统设计的问题,一个front end, 一个back end。 front end有很多UI,一个UI对10个多customers,back end有许多processor,或者processor有多个进程、线程。问应该怎么设计这个并行分布运算的系统,才能让独立的任务得到优化。完全那... 阅读全文
posted @ 2014-09-24 13:21 neverlandly 阅读(875) 评论(1) 推荐(0)
VMware coding Challenge

摘要:思路:这道题要观察,举个例子,1 2 * * 3 * 4 5 * * 6 7 * 8 * *, 用Stack,先序遍历,遇到数字就入栈,如果遇到 * *,说明栈顶节点是叶子节点,一条根到叶子的路径这时候就存在于栈之中,只要计算栈的size(),就知道当前这条路径的深度,树的height就是这些深度的... 阅读全文
posted @ 2014-09-23 22:53 neverlandly 阅读(922) 评论(0) 推荐(0)
Leetcode: Maximal Rectangle

摘要:难度:90 这是一道非常综合的题目,要求在0-1矩阵中找出面积最大的全1矩阵。刚看到这道题会比较无从下手,brute force就是对于每个矩阵都看一下,总共有m(m+1)/2*n(n+1)/2个子矩阵(原理跟字符串子串类似,字符串的子串数有n(n+1)/2,只是这里是二维情形,所以是两个相乘),复 阅读全文
posted @ 2014-09-22 05:56 neverlandly 阅读(435) 评论(0) 推荐(0)
Leetcode: Largest Rectangle in Histogram

摘要:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the hist... 阅读全文
posted @ 2014-09-22 01:10 neverlandly 阅读(494) 评论(0) 推荐(0)
Leetcode: Sum Root to Leaf Numbers

摘要:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which... 阅读全文
posted @ 2014-09-21 06:47 neverlandly 阅读(481) 评论(0) 推荐(0)
Leetcode: LRU Cache

摘要:难度:90。这是一道非常综合的题目,主要应用在操作系统的资源管理中。 按照题目要求,要实现get和set功能,为了满足get功能:随机访问的需求(lookup)我们首先想到的一般是用数组,如果用链表会有O(n)的访问时间。然而他又有另一个条件就是要维护least used的队列,也就是说经常用的放在 阅读全文
posted @ 2014-09-21 05:31 neverlandly 阅读(723) 评论(0) 推荐(0)
Leetcode: Candy

摘要:贪心法 复杂度 时间 O(N) 空间 O(N) 思路 典型的贪心法,如果一个孩子比另一个孩子的分高,我们只多给1块糖。我们可以先从左往右遍历,确保每个孩子根他左边的孩子相比,如果分高,则糖要多1个,如果分比左边低,就只给一颗。然后我们再从右往左遍历,确保每个孩子跟他右边的孩子相比,如果分高则糖至少多 阅读全文
posted @ 2014-09-20 13:18 neverlandly 阅读(335) 评论(0) 推荐(0)
Leetcode: Interleaving String

摘要:难度:87. 这是一道关于字符串操作的题目,要求是判断一个字符串能不能由两个字符串按照他们自己的顺序,每次挑取两个串中的一个字符来构造出来。像这种判断能否按照某种规则来完成求是否或者某个量的题目,很容易会想到用动态规划来实现。 动态规划重点在于找到:维护量,递推式。维护量通过递推式递推,最后往往能得 阅读全文
posted @ 2014-09-20 12:26 neverlandly 阅读(385) 评论(0) 推荐(0)
Leetcode: Implement strStr()

摘要:暴力法 复杂度 时间 O(N^2) 空间 O(N)因为用了一个临时string存 思路 本题有很多高级算法可以在O(N)时间内解决问题,然而这已经超出面试的范畴。本题在面试中出现的作用就是考察基本的编程素养,以及边界条件的考虑。我们用暴力法即可。 若要用O(1)的space,就一个一个比: 推荐: 阅读全文
posted @ 2014-09-20 10:58 neverlandly 阅读(521) 评论(0) 推荐(0)
Leetcode: Gray Code

摘要:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total numb... 阅读全文
posted @ 2014-09-20 07:15 neverlandly 阅读(431) 评论(0) 推荐(0)
Leetcode: Restore IP addresses

摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255... 阅读全文
posted @ 2014-09-20 06:48 neverlandly 阅读(401) 评论(0) 推荐(0)
Leetcode: Median of Two Sorted Arrays

摘要:2017/2/5更新:如果一定要每次扔一半,使得时间复杂度为O(log(m+n))。可以在第一个数组找前k1个,第二个数组找前k2个,使得k1+k2 == k, 分情况: 1. if A[k1] < B[k2], then A[k1]及之前的、B[k2+1]及之后的都不可能成为第k个元素,所以扔掉 阅读全文
posted @ 2014-09-20 04:55 neverlandly 阅读(538) 评论(0) 推荐(0)
Leetcode: Pow(x, n) and Summary: 负数补码总结

摘要:Analysis: Time Complexity: O(LogN) Iterative code: refer to https://discuss.leetcode.com/topic/40546/iterative-log-n-solution-with-clear-explanation N 阅读全文
posted @ 2014-09-20 00:32 neverlandly 阅读(990) 评论(0) 推荐(0)
Leetcode: Sort Colors

摘要:难度:naive做法60,计数排序 scan两次也是一种办法,第一次把1和2当做一种颜色,放到0的右边,第二次0已经全部在左边,只需把2放到1右边 我们考虑怎么用一次扫描来解决。 Best Solution(Discuss里vote最高): the basic idea is to use two 阅读全文
posted @ 2014-09-19 12:58 neverlandly 阅读(297) 评论(0) 推荐(0)
Leetcode: Sqrt(x)

摘要:Implement int sqrt(int x). 难度:76,用二分查找。要求是知道结果的范围,取定左界和右界,然后每次砍掉不满足条件的一半,知道左界和右界相遇。算法的时间复杂度是O(logx),空间复杂度是O(1)。 1 public class Solution { 2 public int 阅读全文
posted @ 2014-09-19 12:09 neverlandly 阅读(524) 评论(0) 推荐(0)
Leetcode: Palindrome Partitioning II

摘要:难度:90. 这道题跟Palindrome Partitioning非常类似,区别就是不需要返回所有满足条件的结果,而只是返回最小的切割数量就可以。做过Word Break的朋友可能马上就会想到,其实两个问题非常类似,当我们要返回所有结果(Palindrome Partitioning和Word B 阅读全文
posted @ 2014-09-19 09:08 neverlandly 阅读(580) 评论(0) 推荐(0)
Leetcode: Palindrome Partitioning

摘要:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example,... 阅读全文
posted @ 2014-09-19 07:33 neverlandly 阅读(594) 评论(0) 推荐(0)
Leetcode: Valid Palindrome

摘要:第二次做法:用API 第一次做法:难度:79. 这道题是判断一个字符串是不是回文串。因为只是看一个字符串,算法还是比较简单,就是从两头出发,往中间走,进行两两匹配。这里面的小问题就是在这个题目要求中,只判断字母和数字类型的字符,其他字符直接跳过即可。因此我们要写一个函数判断他是不是合法字符,而且因为 阅读全文
posted @ 2014-09-19 05:36 neverlandly 阅读(466) 评论(0) 推荐(0)
Leetcode: Symmetric Tree

摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文
posted @ 2014-09-19 04:35 neverlandly 阅读(268) 评论(0) 推荐(0)
Leetcode: Validate Binary Search Tree

摘要:需要保证的是左子树所有节点都小于根,而并非仅仅左子树根。所以Recursion里面要存的是可以取值的范围。其实就是对于每个结点保存左右界,也就是保证结点满足它的左子树的每个结点比当前结点值小,右子树的每个结点比当前结点值大。对于根节点不用定位界,所以是无穷小到无穷大,接下来当我们往左边走时,上界就变 阅读全文
posted @ 2014-09-19 03:29 neverlandly 阅读(824) 评论(1) 推荐(0)
Leetcode: Recover Binary Search Tree

摘要:难度:89. 这道题是要求恢复一颗有两个元素调换错了的二叉查找树。一开始拿到可能会觉得比较复杂,其实观察出规律了就比较简单。主要还是利用二叉查找树的主要性质,就是中序遍历是有序的性质。那么如果其中有元素被调换了,意味着中序遍历中必然出现违背有序的情况。那么会出现几次呢?有两种情况,如果是中序遍历相邻 阅读全文
posted @ 2014-09-19 00:52 neverlandly 阅读(388) 评论(0) 推荐(0)
Leetcode: Search in Rotated Sorted Array II

摘要:Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function ... 阅读全文
posted @ 2014-09-18 12:18 neverlandly 阅读(350) 评论(0) 推荐(0)
Leetcode: Search in Rotated Sorted Array

摘要:根据binary search,每次我们都可以切掉一半的数据,所以算法的时间复杂度是O(logn),空间复杂度是O(1)。 阅读全文
posted @ 2014-09-18 11:38 neverlandly 阅读(321) 评论(0) 推荐(0)
Leetcode: Populating Next Right Pointers in Each Node II

摘要:层次递进法 复杂度 时间 O(N) 空间 O(1) 阅读全文
posted @ 2014-09-18 07:01 neverlandly 阅读(402) 评论(0) 推荐(0)
Leetcode: Populating Next Right Pointers in Each Node

摘要:复杂度 时间 O(N) 空间 O(N) 思路 相当于是Level Order遍历二叉树。通过一个Queue来控制每层的遍历,注意处理该层最后一个节点的特殊情况。此方法同样可解第二题。 没想到的方法:因为guarantee了是perfect binary tree 层次递进法 复杂度 时间 O(N) 阅读全文
posted @ 2014-09-18 06:38 neverlandly 阅读(372) 评论(0) 推荐(0)
Summary: Difference between null and empty String

摘要:String s1 = "";means that the emptyStringis assigned tos1. In this case,s1.length()is the same as"".length(), witch will yield0as expected.String s2 =... 阅读全文
posted @ 2014-09-18 06:22 neverlandly 阅读(222) 评论(0) 推荐(0)
Summary: Deep Copy vs. Shallow Copy vs. Lazy Copy

摘要:Object copyAnobject copyis an action in computing where a data object has itsattributescopied to another object of the same data type. Anobjectis a co... 阅读全文
posted @ 2014-09-18 06:13 neverlandly 阅读(575) 评论(0) 推荐(0)
Leetcode: Remove Duplicates from Sorted List II

摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2-... 阅读全文
posted @ 2014-09-18 04:35 neverlandly 阅读(367) 评论(0) 推荐(0)
Leetcode: Copy List with Random Pointer

摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ... 阅读全文
posted @ 2014-09-18 03:18 neverlandly 阅读(449) 评论(0) 推荐(0)
Leetcode: Sort List

摘要:记得Insert Sort List, 那个复杂度是O(N^2)的,这里要求O(nlogn),所以想到merge sort, 需要用到Merge Two Sorted List的方法(我写的merge函数) 第二遍代码:所以mergesort不好写在于它是一个递归里嵌套另一个递归,第一个递归不停地用 阅读全文
posted @ 2014-09-18 00:31 neverlandly 阅读(372) 评论(0) 推荐(0)
Leetcode: Insertion Sort List

摘要:Sort a linked list using insertion sort.我原本的想法是用额外的空间拷贝每一个节点,建立了一个新的sorted的LinkedList, 后来看到别人的做法不用建立新的LinkedList, 直接以原有List上的节点组成新的sorted的LinkedList。我... 阅读全文
posted @ 2014-09-17 12:12 neverlandly 阅读(390) 评论(0) 推荐(0)
Leetcode Binary Tree Zigzag level Order Traversal

摘要:参考这道题其实还是树的层序遍历Binary Tree Level Order Traversal。不过这里稍微做了一点变体。在Binary Tree Level Order Traversal中我们是维护了一个队列来完成遍历,而在这里为了使每次都倒序出来,我们很容易想到用栈的结构来完成这个操作。有一 阅读全文
posted @ 2014-09-16 14:17 neverlandly 阅读(386) 评论(0) 推荐(0)
Leetcode: Construct Binary Tree from Inorder and Postorder Traversal

摘要:Given inorder and postorder traversal of a tree, construct the binary tree.与Construct Binary Tree from Inorder and Preorder Traversal问题非常类似,唯一区别在于这一次确... 阅读全文
posted @ 2014-09-16 10:59 neverlandly 阅读(357) 评论(0) 推荐(0)
Leetcode: Construct Binary Tree from Preorder and Inorder Traversal

摘要:难度:95,参考了网上的思路。这道题是树中比较有难度的题目,需要根据先序遍历和中序遍历来构造出树来。这道题看似毫无头绪,其实梳理一下还是有章可循的。下面我们就用一个例子来解释如何构造出树。假设树的先序遍历是12453687,中序遍历是42516837。这里最重要的一点就是先序遍历可以提供根的所在,而 阅读全文
posted @ 2014-09-16 10:33 neverlandly 阅读(495) 评论(0) 推荐(0)
Leetcode: Flatten Binary Tree to Linked List

摘要:第二遍做法:不用ArrayList来wrap up previous node, 直接把previous node做成全局变量 第一遍做法:用递归来解决,维护先序遍历的前一个结点pre,然后每次把pre的左结点置空,右结点设为当前结点。这里需要注意的一个问题就是我们要先把左右子结点(Code Gan 阅读全文
posted @ 2014-09-16 04:24 neverlandly 阅读(488) 评论(0) 推荐(0)
Leetcode: Binary Tree Level Order Transversal II

摘要:第二遍方法: 这道题在groupon面经里面有,有一个follow up 是能不能右对齐输出。那就在29行记录每一行的最大size,然后在输出的时候根据最大size补齐空格 在Binary Tree Level Order Transversal的基础上难度:20,只需要对最后结果做一个倒序就好。格 阅读全文
posted @ 2014-09-15 13:30 neverlandly 阅读(389) 评论(0) 推荐(0)
Leetcode: Binary Tree Level Order Traversal

摘要:Best approach: 把树看成一个有向图,进行BFS。BST的通常做法都是维护一个队列。这道题的难度在于,如何在队列不断的入队出队操作中,确定哪些node是一个层次的。想了很久没什么好办法,参考了网上的做法,发现他在维护两个数:一个是父节点所在层次的节点在当前队列中的数目ParentNumI 阅读全文
posted @ 2014-09-15 12:52 neverlandly 阅读(571) 评论(0) 推荐(0)
Leetcode: Binary Tree Postorder Transversal

摘要:难度:70 recursive方法很直接: Iterative 最优做法: pre-order traversal is root-left-right. post-order traversal is left-right-root. We can modify pre-order travers 阅读全文
posted @ 2014-09-15 10:20 neverlandly 阅读(284) 评论(0) 推荐(0)
Leetcode: Binary Tree Inorder Transversal

摘要:recursive 方法: Iterative method: 参考了一下网上的思路,其实就是用一个栈来模拟递归的过程。所以算法时间复杂度也是O(n),空间复杂度是栈的大小O(logn)。 阅读全文
posted @ 2014-09-15 08:49 neverlandly 阅读(420) 评论(0) 推荐(0)
Leetcode: Word Break II

摘要:难度:98,参考了别人的思路:这道题目要求跟Word Break比较类似,不过返回的结果不仅要知道能不能break,如果可以还要返回所有合法结果。一般来说这种要求会让动态规划的效果减弱很多,因为我们要在过程中记录下所有的合法结果,中间的操作会使得算法的复杂度不再是动态规划的两层循环,因为每次迭代中还 阅读全文
posted @ 2014-09-14 11:21 neverlandly 阅读(938) 评论(0) 推荐(0)
Leetcode: Word Break

摘要:首先我们要决定要存储什么历史信息以及用什么数据结构来存储信息。然后是最重要的递推式,就是如从存储的历史信息中得到当前步的结果。最后我们需要考虑的就是起始条件的值。 接下来我们套用上面的思路来解这道题。首先我们要存储的历史信息res[i]是表示到字符串s的第i个元素为止能不能用字典中的词来表示,我们需 阅读全文
posted @ 2014-09-13 12:22 neverlandly 阅读(416) 评论(0) 推荐(0)
Leetcode: Maximum Subarray

摘要:思想难度:99,操作难度:50。思想大于行动的一项有力证明。这是一道非常经典的动态规划的题目,用到的思路我们在别的动态规划题目中也很常用,以后我们称为”局部最优和全局最优解法“。差不多的DP问题参见:Jump Game, Jump Game II基本思路是这样的,在每一步,我们维护两个变量,一个是全 阅读全文
posted @ 2014-09-12 13:40 neverlandly 阅读(349) 评论(0) 推荐(0)
Leetcode: Jump Game II

摘要:难度:89,这道题参考了网上的解法:和Jump Game很像,只是原来的全局最优现在要分成step步最优和step-1步最优(假设当前步数是step)。当走到超过step-1步最远的位置时,说明step-1不能到达当前一步,我们就可以更新步数,将step+1。时间复杂度仍然是O(n),空间复杂度也是 阅读全文
posted @ 2014-09-12 12:49 neverlandly 阅读(317) 评论(0) 推荐(0)
Leetcode: Jump Game

摘要:Greedy Solution 阅读全文
posted @ 2014-09-12 05:28 neverlandly 阅读(405) 评论(0) 推荐(0)
Leetcode: N-Queens II

摘要:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.跟N-Queen的考虑方式完全一样,NP问题,用循环递... 阅读全文
posted @ 2014-09-11 12:49 neverlandly 阅读(357) 评论(0) 推荐(0)
Leetcode: N-Queens

摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integern, return all di... 阅读全文
posted @ 2014-09-11 10:01 neverlandly 阅读(503) 评论(0) 推荐(0)
Leetcode: Sudoku Solver

摘要:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be o... 阅读全文
posted @ 2014-09-11 06:56 neverlandly 阅读(420) 评论(0) 推荐(0)
Leetcode: Binary Tree Maximum Path Sum

摘要:难度:75. 参见了他人的思路,这道题是求树的路径和的题目,不过和平常不同的是这里的路径不仅可以从根到某一个结点,而且路径可以从左子树某一个结点,然后到达右子树的结点,就像题目中所说的可以起始和终结于任何结点。函数的返回值定义为以自己为根的一条从根到叶子结点的最长路径,这个返回值是为了提供给它的父结 阅读全文
posted @ 2014-09-08 13:12 neverlandly 阅读(404) 评论(0) 推荐(0)
Leetcode: Gas Station

摘要:难度:60.这道题用Brute Force的方法解比较好想,就是从每一个站开始,一直走一圈,累加过程中的净余的油量,看它是不是有出现负的,如果有则失败,从下一个站开始重新再走一圈;如果没有负的出现,则这个站可以作为起始点,成功。可以看出每次需要扫描一圈,对每个站都要做一次扫描,所以时间复杂度是O(n 阅读全文
posted @ 2014-09-08 12:53 neverlandly 阅读(374) 评论(0) 推荐(0)
Leetcode: Convert Sorted List to Binary Search Tree

摘要:目前做法: 第一遍做法:难度70,与Convert Sorted Array to Binary Search Tree问题相似,这道题的做法就是,我们需要中点来做每一层树的根,问题在于,对于一个链表我们是不能常量时间访问它的中间元素的。于是我的想法是花O(N)的时间把链表里面的元素先存到一个数组或 阅读全文
posted @ 2014-09-08 05:21 neverlandly 阅读(610) 评论(0) 推荐(0)
Leetcode: Permutations II

摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique per... 阅读全文
posted @ 2014-09-07 23:46 neverlandly 阅读(436) 评论(0) 推荐(0)
Leetcode: Reorder List && Summary: Reverse a LinkedList

摘要:这是一道比较综合的链表操作的题目,要按照题目要求给链表重新连接成要求的结果。其实理清思路也比较简单,分三步完成:(1)将链表切成两半,也就是找到中点,然后截成两条链表;(2)将后面一条链表进行reverse操作,就是反转过来;(3)将两条链表按顺序依次merge起来。 这几个操作都是我们曾经接触过的 阅读全文
posted @ 2014-09-07 12:07 neverlandly 阅读(479) 评论(0) 推荐(0)
Leetcode: Unique Binary Search Trees II

摘要:难度:98。没有做出来的一道题,很难,参考了其他人的想法,发现基本上只有一个版本,在纸上按照它的步骤推了几步终于看懂了。分析如下: 第一次遇到这种让你construct a BST的问题,而且结果并不是建立一个ArrayList<ArrayList<Integer>>型的,而是建立一个ArrayLi 阅读全文
posted @ 2014-09-07 07:26 neverlandly 阅读(449) 评论(0) 推荐(0)
Leetcode: Subsets II

摘要:第二遍Better做法: 第11行 i>start && nums[i]==nums[i-1] 就skip很不错 第一遍做法:需要已访问数组,当前后元素一样且前面元素并未访问,这个时候就是重复的case, continue, 注意这里的判重复条件跟3Sum那种是不一样的, 3SUM防止重复方法是 i 阅读全文
posted @ 2014-09-06 07:11 neverlandly 阅读(505) 评论(0) 推荐(0)
Leetcode: Unique Paths II

摘要:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space i... 阅读全文
posted @ 2014-09-06 05:22 neverlandly 阅读(476) 评论(0) 推荐(0)
Leetcode: Minimum Path Sum

摘要:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. 阅读全文
posted @ 2014-09-06 04:24 neverlandly 阅读(476) 评论(0) 推荐(0)
Leetcode: Multiply Strings

摘要:大整数的字符串乘法,我本来对字符串表示的大整数就不是太熟悉,至于溢出该怎么处理也是不大清楚,所以参考了别人的做法,然后自己凭着印象重做了一次 直接乘会溢出,所以每次都要两个single digit相乘,最大81,不会溢出。 比如385 * 97, 就是个位=5 * 7,十位=8 * 7 + 5 * 阅读全文
posted @ 2014-09-05 11:06 neverlandly 阅读(591) 评论(0) 推荐(0)
Leetcode: Distinct Subsequences

摘要:DP新思路,不同于以往的DP做法 阅读全文
posted @ 2014-09-05 05:18 neverlandly 阅读(359) 评论(0) 推荐(0)

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3