微软面试一百道题目精选6082.docx
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《微软面试一百道题目精选6082.docx》由会员分享,可在线阅读,更多相关《微软面试一百道题目精选6082.docx(75页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、第9 题题判断整整数序列列是不是是二元查查找树的的后序遍遍历结果果题目:输入一一个整数数数组,判判断该数数组是不不是某二二元查找找树的后后序遍历历的结果果。如果果是返回回truue,否否则返回回fallse。例如输输入5、7、6、9、11、10、8,由于于这一整整数序列列是如下下树的后后序遍历历结果:8/ 6 110/ / 55 7 9 111因此此返回ttruee。如果输输入7、4、6、5,没有有哪棵树树的后序序遍历的的结果是是这个序序列,因因此返回回fallse。ANSSWERR:Thiis iis aan iinteeresstinng oone. Thheree iss a traad
2、ittionnal queestiion thaat rrequuirees tthe binnaryy trree to be re-connstrructted froom mmid/posst/ppre ordder ressultts. Thiis sseemms ssimiilarr. FFor thee prrobllemss reelatted to (biinarry) treees, reecurrsioon iis tthe firrst chooicee.In thiis pprobblemm, wwe kknoww inn poost-ordder ressultts,
3、 thee laast nummberr shhoulld bbe tthe rooot. So we havve kknowwn tthe rooot oof tthe BSTT iss 8 in thee exxampple. Soo wee caan sspliit tthe arrray by thee rooot.intt issPosstorrderrRessultt(innt aa, innt nn) rretuurn hellperr(a, 0, n-1);intt heelpeer(iint a, iint s, intt e) iff (ee=ss) rretuurn 1;
4、 innt ii=e-1; whhilee (aaeai & i=s) i-; if (!hhelpper(a, i+11, ee-1) rretuurn 0; innt kk = l; whhilee (aae=s) i-; retturnn heelpeer(aa, ss, ll);第10 题翻转句句子中单单词的顺顺序。题题目:输输入一个个英文句句子,翻翻转句子子中单词词的顺序序,但单单词内字字符的顺顺序不变变。句子子中单词词以空格格符隔开开。为简简单起见见,标点点符号和和普通字字母一样样处理。例如输入“I am a student.”,则输出“student. a am I”。Answe
5、r:Already done this. Skipped.第11 题求二叉叉树中节节点的最最大距离离.如果我我们把二二叉树看看成一个个图,父父子节点点之间的的连线看看成是双双向的,我们姑且定义距离为两节点之间边的个数。写一个程序,求一棵二叉树中相距最远的两个节点之间的距离。ANSWER:This is interesting. Also recursively, the longest distance between two nodes must be either from root to one leaf, or between two leafs. For the former cas
6、e, its the tree height. For the latter case, it should be the sum of the heights of left and right subtrees of the two leaves most least ancestor.The first case is also the sum the heights of subtrees, just the height + 0.int maxxDisstannce(Nodde * rooot) innt ddeptth; reeturrn hhelpper(rooot, deppt
7、h);intt heelpeer(NNodee * rooot, intt &ddeptth) if (rooot = NULLL) ddeptth = 0; reeturrn 00; intt ldd, rrd; innt mmaxlleftt = hellperr(rooot-leeft, ldd); innt mmaxrrighht = heelpeer(rroott-rrighht, rd); deppth = mmax(ld, rdd)+11; retturnn maax(mmaxlleftt, mmax(maxxrigght, ldd+rdd);第12 题题目:求1+2+n,要求不
8、不能使用用乘除法法、foor、whiile、if、elsse、swiitchh、casse 等等关键字字以及条条件判断断语句(A?BB:C)。ANNSWEER:1+.+nn=n*(n+1)/2=(n22+n)/2iit iis eeasyy too geet xx/2, soo thhe pprobblemm iss too geet nn2tthouugh no if/elsse iis aalloowedd, wwe ccan eassillly ggo aarouund usiing shoort-passs.uusinng mmacrro tto mmakee itt faanciie
9、r:#deffinee TT(X, Y, i) (YY & (1i) & XX+=(Y 11;第13 题:题目目:输入入一个单单向链表表,输出出该链表表中倒数数第k 个结点。链链表的倒倒数第00 个结点为为链表的的尾指针针。链表表结点定定义如下下:sttrucct LListtNoddeintt m_nKeey;LListtNodde* m_ppNexxt;Annsweer:Twoo waays. 1: reecorrd tthe lenngthh off thhe llinkked lisst, theen ggo nn-k steeps. 2: usse ttwo currsorrs.TT
10、imee coompllexiitiees aare exaactlly tthe samme.Nodde * laastKK(Noode * hheadd, iint k) if (k0) errror(“k 00;k-) iif (pk-neext!=NUULL) pkk = pk-neext; ellse retturnn NUULL; wwhille (pk-neext!=NUULL) p=pp-nnextt, ppk=ppk-nexxt; reeturrn pp;第14 题:题目目:输入入一个已已经按升升序排序序过的数数组和一一个数字字,在数数组中查查找两个个数,使使得它们们的和正正
11、好是输输入的那那个数字字。要求求时间复复杂度是是O(nn)。如如果有多多对数字字的和等等于输入入的数字字,输出出任意一一对即可可。例如如输入数数组1、2、4、7、11、15 和数字字15。由由于4+11=15,因因此输出出4 和11。ANSSWERR:Usee twwo ccurssorss. OOne at froont andd thhe ootheer aat tthe endd. KKeepp trrackk off thhe ssum by movvingg thhe ccurssorss.vooid finnd2NNumbber(intt a, intt n, innt ddest
12、t) iint *f = aa, *e=aa+n-1; innt ssum = *f + *ee; whiile (suum != ddestt & f ee) iff (ssum leeft), &(rooot-riightt); mmirrror(rooot-lefft); mmirrror(rooot-rigght);voidd miirroorItteraativvelyy(Noode * rroott) iif (rooot = NNULLL) rretuurn; sstacck buff; buff.puush(rooot); wwhille (!sttackk.emmptyy()
13、 Nodde * n = sstacck.ppop(); swaap(&(rooot-leeft), &(rooot-riightt); iff (rroott-lleftt != NUULL) buuf.ppushh(rooot-leeft); iif (rooot-rigght != NULLL) buff.puush(rooot-rigght); 第16 题:题目目(微软软):输输入一颗颗二元树树,从上上往下按按层打印印树的每每个结点点,同一一层中按按照从左左往右的的顺序打打印。例例如输入入8/ 6 110/ / 55 7 9 111输出出8 66 100 5 7 99 111。ANSS
14、WERR:Thee noodess inn thhe lleveels aree prrintted in thee siimillar mannnerr thheirr paarennts werre pprinntedd. SSo iit sshouuld be an FIFFO qqueuue tto hholdd thhe lleveel. I rreallly donnt remmembber thee fuuncttionn naame of thee sttl qqueuue, so I wwilll wrritee itt inn Jaava.vvoidd prrinttByL
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 微软 面试 一百 题目 精选 6082
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内