C++编程,数据结构,算法类面试题集(4)(二)

2014-11-24 01:26:03 · 作者: · 浏览: 15
greenend.org.uk/~sgtatham/algorithms/listsort.html


Merge sort linked list的特点:不需要额外空间,时间复杂度O(NlogN),并且是stable的



117. example:
char *words[] = {“foo”, “bar”, “baz”, NULL};
setup(words);
1) First step:
isMember(“foo”) -> true
isMember(“garply”) -> false


2) Second step:
isMember(“f.o”) -> true
isMember(“..”) -> false
*/


1. 用map即可。。。


2. 需要对words里面的每一个elements依次匹配。为了加速,可以预先对words构建一棵字典树。



118. Given an integer, print the next smallest and next largest number that has the same number of 1 bits in their binary representation.


xxx011100 -> xxx100011


CODE略



119. 一个有n个整数数列,如果有符合下面条件,就返回1,如果没有返回0.


要求:a[i]+a[j]>a[k]; a[i]+a[k]>a[j]; a[j]+a[k]>a[i]


先排序,再比较相邻的三个数即可



120 很长很长的string/file, 要我找出中间重复次数最多的character, character set
可能是任何char set, unicode. (map reduce, multi-thread)


TO LEARN, 写一下用map reduce 怎么做