上一页 1 ··· 6 7 8 9 10 11 12 13 14 下一页

2013年9月28日

Jump Game II

摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximu... 阅读全文

posted @ 2013-09-28 07:16 Step-BY-Step 阅读(203) 评论(0) 推荐(0) 编辑

Google 面经 09/26

摘要: http://www.mitbbs.com/article_t/JobHunting/32539885.html狗家面经发信站: BBS 未名空间站 (Thu Sep 26 01:20:54 2013, 美东)还不知道结果,披个马甲攒人品吧1. 二叉树的序列化和反序列化,节点的value是String类型2. 找两个排好序的list的共同元素 5 -> 6 -> 6 ->8 4 -> 4-> 6 -> 6 -> 8答案是 6 -> 6 -> 8两个list长度差不多是怎么做? 长度相差非常大时如何做?3. 有一个字典因为某种原因每个字符都被 阅读全文

posted @ 2013-09-28 05:42 Step-BY-Step 阅读(332) 评论(0) 推荐(0) 编辑

2013年9月27日

Word Search

摘要: Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.For example,Givenboard=[ [&q 阅读全文

posted @ 2013-09-27 12:12 Step-BY-Step 阅读(253) 评论(0) 推荐(0) 编辑

Remove Duplicates from Sorted List

摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.Solution:稍微修改上一个代码即可,遇到次数多于1的,先输出一个,然后将hashmap中标记一下(这里我就是将其value改为0),后面就不输出它即可。 1 /** 2 * Definition for singly-l 阅读全文

posted @ 2013-09-27 12:05 Step-BY-Step 阅读(200) 评论(0) 推荐(0) 编辑

Remove Duplicates from Sorted List II

摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.Solution:首先用hashmap计算每个元素出现的次数,然后给list加个头指针,然后遍历链表,将次 阅读全文

posted @ 2013-09-27 07:22 Step-BY-Step 阅读(135) 评论(0) 推荐(0) 编辑

Largest Rectangle in Histogram

摘要: Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height =[2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has ar 阅读全文

posted @ 2013-09-27 05:27 Step-BY-Step 阅读(374) 评论(0) 推荐(0) 编辑

Scramble String

摘要: Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string, we may choose any non-leaf no... 阅读全文

posted @ 2013-09-27 03:35 Step-BY-Step 阅读(257) 评论(0) 推荐(0) 编辑

2013年9月26日

Maximal Rectangle

摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.看到2D,首先想到的就是那个二维矩阵中找最大子矩阵。同样也是可以降级到一维:给一个array,里面有1 和 0, 找联续1的最大长度。这个问题很好解决,即function findMax。然后再递归到二维即可。方法是先把bot定为最底层,然后把top从bot往上移,如果竖向看全1,则将抽象这个矩形的数组本位设为1,否则为0。然后找最大长度,乘上其放 阅读全文

posted @ 2013-09-26 13:45 Step-BY-Step 阅读(295) 评论(0) 推荐(0) 编辑

Partition List

摘要: Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of the two partitions.For example,Given1->4->3->2->5->2andx= 3,return1->2->2->4->3- 阅读全文

posted @ 2013-09-26 12:09 Step-BY-Step 阅读(259) 评论(0) 推荐(0) 编辑

Multiply Strings

摘要: Given two numbers represented as strings, returnmultiplication of thenumbers as a string.Note: The numbers can be arbitrarily large and are non-negati... 阅读全文

posted @ 2013-09-26 07:36 Step-BY-Step 阅读(212) 评论(0) 推荐(0) 编辑

Gray Code

摘要: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code s 阅读全文

posted @ 2013-09-26 06:58 Step-BY-Step 阅读(251) 评论(0) 推荐(0) 编辑

Decode Ways

摘要: A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it cou 阅读全文

posted @ 2013-09-26 06:52 Step-BY-Step 阅读(187) 评论(0) 推荐(0) 编辑

Unique Binary Search Trees II

摘要: Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ ... 阅读全文

posted @ 2013-09-26 02:44 Step-BY-Step 阅读(194) 评论(0) 推荐(0) 编辑

Unique Binary Search Trees

摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's.1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文

posted @ 2013-09-26 02:35 Step-BY-Step 阅读(205) 评论(0) 推荐(0) 编辑

2013年9月25日

Interleaving String

摘要: Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="... 阅读全文

posted @ 2013-09-25 06:59 Step-BY-Step 阅读(190) 评论(0) 推荐(0) 编辑

线索二叉树Threaded binary tree

摘要: 摘要按照某种遍历方式对二叉树进行遍历,可以把二叉树中所有结点排序为一个线性序列。在该序列中,除第一个结点外每个结点有且仅有一个直接前驱结点;除最后一个结点外每一个结点有且仅有一个直接后继结点。这些指向直接前驱结点和指向直接后续结点的指针被称为线索(Thread),加了线索的二叉树称为线索二叉树。编辑本段概念n个结点的二叉链表中含有n+1(2n-(n-1)=n+1)个空指针域。利用二叉链表中的空指针域,存放指向结点在某种遍历次序下的前趋和后继结点的指针(这种附加的指针称为"线索")。这种加上了线索的二叉链表称为线索链表,相应的二叉树称为线索二叉树(Threaded Binar 阅读全文

posted @ 2013-09-25 06:41 Step-BY-Step 阅读(656) 评论(0) 推荐(0) 编辑

Recover Binary Search Tree

摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ... 阅读全文

posted @ 2013-09-25 06:06 Step-BY-Step 阅读(334) 评论(0) 推荐(0) 编辑

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 / \ 2 2 / \ / \3 4 4 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:Bonus points if you could solve it both recursively and iterati... 阅读全文

posted @ 2013-09-25 03:05 Step-BY-Step 阅读(122) 评论(0) 推荐(0) 编辑

2013年9月24日

Triangle

摘要: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11(i.e.,2+3+5+1= 11).Note:Bonus point if you areab... 阅读全文

posted @ 2013-09-24 07:26 Step-BY-Step 阅读(237) 评论(0) 推荐(0) 编辑

常见的设计模式

摘要: 创建型设计模式:与对象的创建有关。结构型设计模式:处理类或对象的组合。行为型设计模式:描述类或对象如何交互及如何分配职责。常见的创建型设计模式有:简单工厂模式;工厂方法模式;抽象工厂模式;建造者模式;原型模式;单例模式。常见的结构型模式:适配器模式;桥接模式;组合模式;装饰模式;外观模式;轻量级模式;代理模式。常见的行为型模式:责任链模式;命令模式;解释模;迭代器模式;中介者模式;备忘录模式;观察者模式;状态模式;策略模式;模板方法模式;访问者模式。创建型模式 1、FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德 阅读全文

posted @ 2013-09-24 05:41 Step-BY-Step 阅读(370) 评论(0) 推荐(0) 编辑

2013年9月14日

HashMap与Hashtable的区别

摘要: HashTable的应用非常广泛,HashMap是新框架中用来代替HashTable的类,也就是说建议使用HashMap,不要使用HashTable。可能你觉得HashTable很好用,为什么不用呢?这里简单分析他们的区别。1.HashTable的方法是同步的,HashMap未经同步,所以在多线程场合要手动同步HashMap这个区别就像Vector和ArrayList一样。2.HashTable不允许null值(key和value都不可以),HashMap允许null值(key和value都可以)。3.HashTable有一个contains(Objectvalue),功能和containsV 阅读全文

posted @ 2013-09-14 06:09 Step-BY-Step 阅读(196) 评论(0) 推荐(0) 编辑

最大子矩阵和

摘要: 前言:今天花了很长时间,看了无数人写的帖子,但是几乎没有人把这个问题一下子说得很清楚,所以,我把这个问题按照自己的思路写出来,希望能够把这个问题讲清楚。问题:求一个M*N的矩阵的最大子矩阵和。比如在如下这个矩阵中:0 -2 -7 09 2 -6 2-4 1 -4 1-1 8 0 -2拥有最大和的子矩阵为:9 2-4 1-1 8其和为15。思路:首先,这个子矩阵可以是任意大小的,而且起始点也可以在任何地方,所以,要把最大子矩阵找出来,我们要考虑多种情况。假定原始矩阵的行数为M,那么对于子矩阵,它的行数可以是1到M的任何一个数,而且,对于一个K行(K 0)?(maxSub[i-1]+array[i 阅读全文

posted @ 2013-09-14 06:04 Step-BY-Step 阅读(544) 评论(1) 推荐(0) 编辑

Binary Tree Level Order Traversal II

摘要: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]解题思路... 阅读全文

posted @ 2013-09-14 05:35 Step-BY-Step 阅读(158) 评论(0) 推荐(0) 编辑

2013年9月13日

外排序

摘要: 外排序(External sorting)是指能够处理极大量数据的排序算法。通常来说,外排序处理的数据不能一次装入内存,只能放在读写较慢的外存储器(通常是硬盘)上。外排序通常采用的是一种“排序-归并”的策略。在排序阶段,先读入能放在内存中的数据量,将其排序输出到一个临时文件,依此进行,将待排序数据组织为多个有序的临时文件。尔后在归并阶段将这些临时文件组合为一个大的有序文件,也即排序结果。目录[隐藏]1外归并排序1.1附加的步骤1.2优化性能2其他算法3外部链接4参考外归并排序[编辑]外排序的一个例子是外归并排序(External merge sort),它读入一些能放在内存内的数据量,在内存中 阅读全文

posted @ 2013-09-13 05:25 Step-BY-Step 阅读(342) 评论(0) 推荐(0) 编辑

微软面试那些事(三轮面试题目+详细分析过程)文章来源: 刘蔚-L的日志

摘要: 先说下写这篇技术贴的原因,三轮面试已经过去一周,这一周也有好多同学问我“微软面的啥。。。”,却而不恭,所以我每次都仔细的回答。最终一遍遍的重复有点小崩溃,还是写篇面经,以造福以后想去微软实习的同学。微软的面试不是很难,而且挺有规律和特点的。这篇日志码了将近三个小时的字儿,很是辛苦。如果您身边有学计算机的朋友,欢迎转发,当他有一天走入中关村微软大厦的那一天,一定会感谢你的哦,吼吼。上题目之前先叨叨点废话。这个月被腾讯和微软两家公司折腾的死去活来,笔试一家一次,一共两次。面试一共十轮,腾讯广州研发部四轮,腾讯全国统一校招三轮,微软三轮,结果还算顺利,两家都拿到了offer,最后决定去北京中关村的微 阅读全文

posted @ 2013-09-13 05:23 Step-BY-Step 阅读(804) 评论(1) 推荐(0) 编辑

2013年9月12日

Convert Sorted List to Binary Search Tree

摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { val = x; next = null; } 7 * } 8 */ 9 /**10 ... 阅读全文

posted @ 2013-09-12 14:46 Step-BY-Step 阅读(462) 评论(0) 推荐(0) 编辑

Balanced Binary Tree

摘要: Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofeverynode never differ by more than 1.the tree is only balanced if:The left and right subtrees' heights differ by at most o 阅读全文

posted @ 2013-09-12 14:28 Step-BY-Step 阅读(173) 评论(0) 推荐(0) 编辑

Minimum Depth of Binary Tree

摘要: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.solution:采用BFS的方式遍历tree即可。 同时为了知道是在哪一层 加入一个每一层结束的signal node。 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int ... 阅读全文

posted @ 2013-09-12 13:47 Step-BY-Step 阅读(169) 评论(0) 推荐(0) 编辑

Path Sum

摘要: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ... 阅读全文

posted @ 2013-09-12 13:02 Step-BY-Step 阅读(135) 评论(0) 推荐(0) 编辑

Flatten Binary Tree to Linked List

摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6Hints:If you notice carefully ... 阅读全文

posted @ 2013-09-12 12:48 Step-BY-Step 阅读(222) 评论(0) 推荐(0) 编辑

Distinct Subsequences

摘要: Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,"ACE" 阅读全文

posted @ 2013-09-12 11:57 Step-BY-Step 阅读(201) 评论(0) 推荐(0) 编辑

2013年9月11日

Chp3: Stacks and Queue

摘要: 1.说明如何用两个队列来实现一个栈,并分析有关栈操作的运行时间。解法:1.有两个队列q1和q2,先往q1内插入a,b,c,这做的都是栈的push操作。2.现在要做pop操作,即要得到c,这时可以将q1中的a,b两个元素全部dequeue并存入q2中,这时q2中元素为a,b,对q1再做一次dequeue操作即可得到c。3.如果继续做push操作,比如插入d,f,则把d,f插入到q2中,4.此时若要做pop操作,则做步骤25.以此类推,就实现了用两个队列来实现一个栈的目的。注意在此过程中,新push进来的元素总是插入到非空队列中,空队列则用来保存pop操作之后的那些元素,那么此时空队列不为空了,原 阅读全文

posted @ 2013-09-11 12:23 Step-BY-Step 阅读(150) 评论(0) 推荐(0) 编辑

Chp2: Linked List

摘要: 2.2 Implement an algorithm to find the kth to last element of a singly linked list.Just using "runner" tech,let the first pointer to run for k step, then start the second pointer, at the same speed.When the first one hit the end, the second one is just on the kth element.2.5(1) input: (7 - 阅读全文

posted @ 2013-09-11 11:14 Step-BY-Step 阅读(273) 评论(0) 推荐(0) 编辑

Populating Next Right Pointers in Each Node

摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL.N... 阅读全文

posted @ 2013-09-11 07:45 Step-BY-Step 阅读(207) 评论(0) 推荐(0) 编辑

Valid Palindrome

摘要: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana... 阅读全文

posted @ 2013-09-11 07:36 Step-BY-Step 阅读(170) 评论(0) 推荐(0) 编辑

Binary Tree Maximum Path Sum

摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 ... 阅读全文

posted @ 2013-09-11 06:34 Step-BY-Step 阅读(203) 评论(0) 推荐(0) 编辑

Best Time to Buy and Sell Stock II

摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at 阅读全文

posted @ 2013-09-11 05:27 Step-BY-Step 阅读(130) 评论(0) 推荐(0) 编辑

Best Time to Buy and Sell Stock

摘要: Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.最简单的方法就是穷举,O(n2)。 1 public class Solution { 2 public in... 阅读全文

posted @ 2013-09-11 05:16 Step-BY-Step 阅读(195) 评论(0) 推荐(0) 编辑

Longest Consecutive Sequence

摘要: Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest ... 阅读全文

posted @ 2013-09-11 02:51 Step-BY-Step 阅读(219) 评论(0) 推荐(0) 编辑

Next Permutation

摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文

posted @ 2013-09-11 01:41 Step-BY-Step 阅读(395) 评论(0) 推荐(0) 编辑

上一页 1 ··· 6 7 8 9 10 11 12 13 14 下一页

导航