摘要: Binary Tree Zigzag Level Order TraversalSep 29 '12Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 ... 阅读全文
posted @ 2013-03-09 11:56 西施豆腐渣 阅读(125) 评论(0) 推荐(0) 编辑
摘要: Balanced Binary TreeOct 9 '12Given 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./** * Definition for binary tree * struct TreeNode { * . 阅读全文
posted @ 2013-03-09 09:46 西施豆腐渣 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 感觉楼主写的太简单,我来补充一下吧,我不是学医的,因为我自己查出来有幽门螺旋杆菌,做的一些research以及和我医生的谈话。我给的数据就是大概我记得的,不一定很准确:幽门螺旋杆菌在不发达国家儿童大概感染率在50%,成人在90%。在发达国家,儿童大概感染率在10%,成人在50%。幽门螺旋杆菌主要是食物不干净造成的,比如,不干净的蔬菜水果,等等。饮食习惯是加剧了传染,但食物不干净是主因。感染幽门螺旋杆菌的人,大概10%会造成胃溃疡,大概10%的胃溃疡,会发展成胃癌。就是说,大概1%的幽门螺旋杆菌感染者会发展成胃癌。从感染幽门螺旋杆菌发展到胃癌,是一个漫长的过程,可能5+年(没有结论具体多长)。测 阅读全文
posted @ 2013-03-08 06:23 西施豆腐渣 阅读(388) 评论(1) 推荐(0) 编辑
摘要: Longest Consecutive SequenceFeb 14Given 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 consecutive elements sequence is[1, 2, 3, 4]. Return its length:4.Your algorithm should run in O(n) complexity.class 阅读全文
posted @ 2013-03-08 04:38 西施豆腐渣 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 一个链表问题:复制带随机指针的链表题目:有一个链表L,其每个节点有2个指针,一个指针next指向链表的下个节点,另一个random随机指向链表中的任一个节点,可能是自己或者为空,写一个程序,要求复制这个链表的结构并分析其复杂性解决方法一:O(n)的复杂度,扫面两边即可。图【1】图【1】是需要复制的链表图【2】如图【2】所示,ABCD是原来的链表,A’B’C’D’是复制的链表,第一遍扫描顺序复制next指针,把ABCD的next分别指向A’B’C’D’,将A’的next指针指向B,B’的next指针指向C,依次类推复制random指针: A’->random=A->random-&g 阅读全文
posted @ 2013-03-07 13:49 西施豆腐渣 阅读(216) 评论(0) 推荐(0) 编辑
摘要: Real world objects are handled very similarly to software object oriented design. Supposeyou are designing an object oriented design for a parking lot:1. What are your goals? For example: !gure out if a parking spot is taken, !gure out howmany cars of each type are in the parking lot, look up handic 阅读全文
posted @ 2013-03-06 07:21 西施豆腐渣 阅读(175) 评论(0) 推荐(0) 编辑
摘要: imagine we’re designing the objects for a deck of cards. Consider the following approach:1. What are you trying to do with the deck of cards? Ask your interviewer. Let’s assumewe want a general purpose deck of cards to implement many di#erent types of cardgames.2. What are the core objects—and what 阅读全文
posted @ 2013-03-06 06:00 西施豆腐渣 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 设计电梯,停车场, 纸牌 和 动物再来一个design的题☆─────────────────────────────────────☆ HNM ( ) 于 (Sun Jan 10 17:17:33 2010, 美东) 提到:一个汽车工厂生产各种各样的车,比如卡车,乘客车等等每辆车有不同特性,比如有的有天窗,有的四个门,有的两个门现在让你设计一个测试车的程序,比如说,想测试电池,那么所有有电池的车都要被测试;如果想测试天窗,那么所有有天窗的车都要被测试.给出class,和主要function.这个又是什么pattern之类的呢?※ 来源:·BBS 未名空间站 海外: mitbbs.c 阅读全文
posted @ 2013-03-05 17:18 西施豆腐渣 阅读(228) 评论(0) 推荐(0) 编辑
摘要: paul198247 (S.Battier) 于 (Mon Jul 12 00:30:59 2010, 美东) 提到:如果让设计一个多部电梯的控制系统,画出uml图。请问大概要设计哪些类,类之间的关系?我是最近才看OOD的,比较菜我是这么想的:主系统System包含了taskcenter,elevator任务系统taskcenter负责给不同电梯增加任务,删除任务,响应不同电梯内的任务请求,每层用户的请求电梯elevator 包括了自己的任务list,方向,以及状态。电梯类有2个子类,一个是UI_elevator,一个是task_elevator。UI_elevator函数有addreques 阅读全文
posted @ 2013-03-05 17:14 西施豆腐渣 阅读(226) 评论(0) 推荐(0) 编辑
摘要: Reverse IntegerDec 26 '11Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!If the integer's last digit is 0, what 阅读全文
posted @ 2013-03-05 16:12 西施豆腐渣 阅读(138) 评论(0) 推荐(0) 编辑