facebook面试题【转】】的更多相关文章

开篇 通常的匹配分为两类,一种是正则表达式匹配,pattern包含一些关键字,比如'*'的用法是紧跟在pattern的某个字符后,表示这个字符可以出现任意多次(包括0次). 另一种是通配符匹配,我们在操作系统里搜索文件的时候,用的就是这种匹配.比如 "*.pdf",'*'在这里就不再代表次数,而是通配符,可以匹配任意长度的任意字符组成的串.所以"*.pdf"表示寻找所有的pdf文件. 在算法题中,往往也会有类似的模拟匹配题,当然考虑到当场实现的时间,会减少通配符数量…
2014-05-02 10:47 题目链接 原题: Given an unordered array of positive integers, create an algorithm that makes sure no group of integers of size bigger than M have the same integers. Input: ,,,,,,,, M = Output: ,,,,,,,, 题目:给定一个未排序的长度为N的整数数组,和一个正整数M.请设计算法,将N…
2014-05-02 10:40 题目链接 原题: Sink Zero in Binary Tree. Swap zero value of a node with non-zero value of one of its descendants so that no node with value zero could be parent of node with non-zero. 题目:把二叉树中的值为0的节点尽量往下沉,保证所有值为0的节点绝不会有非0的子节点. 解法:我写的算法是O(n…
2014-05-02 10:07 题目链接 原题: Mapping ' = 'A','B','C' ' = 'D','E','F' ... ' = input: output :ouput = [AAD, BBD, CCD, AAE, AAF, BBE, BBF, CCE, CCF] 题目:电话的数字按键和字母有个映射关系,给定一串数字,请给出所有可能的字符映射方式. 解法:此人也不给个描述,搞的下面一堆人来猜题意.这个题目的意思是说,对于给定的数字串,有多少种不同的映射方式.像“112” ->…
2014-05-02 09:59 题目链接 原题: Group Anagrams input = ["star, astr, car, rac, st"] output = [["star, astr"],["car","rac"],["st"]); 题目:给定一堆字符串,设法把anagram都排在一起. 解法:自定义一个comparator,互为anagram的两个字符串在排好序以后是相同的.根据这个规则…
2014-05-02 09:54 题目链接 原题: You have two numbers decomposed in binary representation, write a function that sums them and returns the result. Input: , Output: 题目:做二进制加法. 解法:字符串就行了,不需要额外开辟数组.string对象本身就是一个vector,也就是一个数组喽. 代码: // http://www.careercup.com…
2014-05-02 09:40 题目链接 原题: Given a number N, write a program that returns all possible combinations of numbers that add up to N, =N) For example, ,,,},{,,},{,},{,}} 题目:给定一个正整数N,求出所有的由正整数加起来等于N的可能组合(加数保持升序).比如N = 4的时候,结果是{{1,1,1,1},{1,1,2},{2,2},{1,3}}…
2014-05-02 08:29 题目链接 原题: Write a function for retrieving the total number of substring palindromes. For example the input is 'abba' then the possible palindromes= a, b, b, a, bb, abba So the result . Updated at //: After the interview I got know tha…
2014-05-02 07:49 题目链接 原题: Given a set of n points (coordinate in 2d plane) within a rectangular space, find out a line (ax+by=c), from which the sum of the perpendicular distances of all the points will be minimum. This can has a general usecase like…
2014-05-02 07:37 题目链接 原题: // merge sorted arrays 'a' and 'b', each with 'length' elements, // in-place into 'b' to form a sorted result. assume that 'b' // has 2*length allocated space. // e.g. a = [1, 3, 5], b = [2, 4, 6] => b = [1, 2, 3, 4, 5, 6] /…