181. void reversePairsOfLinkList(Node*& head) {}
[] => []
[A,B] => [B, A]
[A, B, C] => [B, A, C]
[A, B, C, D, E, F, G] => [B, A, D, C, F, E, G]
¼û195Ìâ
182. You have to paint N boards of length {B1, B2, B3¡ BN}. There are K painters available and you are also given how much time a painter takes to paint 1 unit of board. You have to get this job done as soon as possible under the constraints that any painter will only paint continuous sections of board, say board {2, 3, 4} or only board {1} or nothing but not board {2, 4, 5}.
know it could be solved by DP. But solution space seems quite big. What is the optimal solution Thx.
DP,ÀàËÆÓÚ103Ìâ
183. Ò»¸örangeµÄÐòÁУ¨Á´±í»òÊý×飩£¬Èç[1,3], [2,6], [8,10]£¬[15,18] д³ÌÐòºÏ²¢ÓÐÖصþµÄrange£¬±ÈÈçÉÏÃæµÄÐòÁкϲ¢Îª[1,6], [8,10], [15,18] Èç¹ûÕâ¸öÐòÁв»ÊǾ²Ì¬µÄ£¬¶øÊÇÒ»¸öÊý¾ÝÁ÷£¬ÈçºÎ ´¦Àí£¿
INTERVAL TREE
184. ʵÏÖatoi£¬Òª¿¼ÂÇÌØÊâµÄÇé¿ö£¬±ÈÈç²»ºÏ·¨µÄÊäÈëµÈµÈ¡£²ÎÕÕÕâ¸ö¶¨Òå
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/
185. word edit distance.
α´úÂëÈçÏ£º
186. longest palindrome substring.
http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/
Èç¹ûÊÇsubstring,ÄÇ¿ÉÒÔ°´ÖÐÐÄλÖÃÒÀ´ÎËÑË÷¡£
Èç¹ûÊÇsubsequence, ÓëËüµÄ·´Çólongest common subsequence¼´¿É
187. Describe and analyze an algorithm to find the longest prefix of a given string that is also a palindrome. For example, the longest palindrome prefix of ILLINOISURBANACHAMPAIGN is ILLI, and the longest palindrome prefix of HYAKUGOJYUUICHI is the single letter S. For full credit, your algorithm should run in O(n) time.
TO LEARN£¬ ºó׺Ê÷£¿
188. ¸øÒ»¸öÊý¾Ý½á¹¹Êý×飬£¨parent, child£©£¬ Öؽ¨¶þ²æÊ÷£¬×ÜÊÇÏÈÓö¼ûleftchild, ÔÙÓö¼ûright child£¬¼ÙÉèÊäÈëûÓÐÎÊÌâ¡£ÒªÇó·µ»Øroot¡£
ÓÃÒ»¸öhashtableÀ´±£´æËùÓмûµ½¹ýµÄ½áµã¡£ Root½áµã¾ÍÊÇûÓÐÔÚchildλÖÃÉϳöÏÖ¹ýµÄ½áµã¡£
189. 1. Á½¸ösorted array, Èç¹ûmerge³ÉÒ»¸öarray¡£
2. Èç¹ûÕâÁ½¸öarrayûÓÐsortÄØ£¿²¢·ÖÎö¸´ÔӶȡ£
3. Èç¹ûÓÐK¸öûÓÐsortedµÄarrayÔõô°ìÄØ£¿
4. Èç¹ûµ±Ç°»úÆ÷ÓÐK¸öcpu£¬ Ôõô´¦ÀíÎÊÌâ3ÄØ£¿¸´ÔӶȷÖÎö¡££¨¿¼ÂÇmultithreading£©
ºóÃ漸ÎʼÙÉèÊÇmerge³ÉÒ»¸ösorted array, ÄÇÕâ¸öÌâ¾ÍÀàËÆÓÚÍⲿÅÅÐòµÄ¶à·¹é²¢¡£
190. ¸ø¶¨Ò»¸ötree£¬ ÿ¸ö½ÚµãÓÐÒ»¸öÊýÖµ£¬ Èç¹ûÕÒµ½Ò»¸ö´Órootµ½leafµÄpath£¬Ê¹µÃÕâ¸öpathÉϵÄËùÓнڵãµÄsum×îС¡£ InterviewerËùÒªµÄ´ð°¸ÊǺÍhashtableÁªÏµÉϵģ¬ÒòΪ¿¼Âǵ½Ê÷ºÜ´óµÄʱºòÐèÒªºÜ³¤µÄʱ¼ä¡£Õâ¸öÌâºÜÈÝÒ×ÓÃrecursiveµÄ·½Ê½½â´ð£¬¿ÉÊÇÕâ¸ö²»ÊÇinterviewerËùÒªµÄ´ð°¸¡£ºóÀ´°´ÕÕinterviewerµÄÒâ¼û£¬»¹ÊÇ»ù±¾Ð´³öÁËÓÃhashtableµÄËã·¨¡£
²»Àí½âÌâÄ¿µÄÒâ˼¡£¡£
191. ¸ø¶¨Ò»¸öûÓÐͨÍù¸¸½ÚµãµÄÁ¬½ÓµÄBST, ÕÒµ½´óÓÚxµÄ×îСµÄÄǸö½Úµã
ÖÐÐò±éÀú¡£ÂÔ¡£¡£
192. ¼¼ÊõÎÊÌâÊÇÕÒÒ»¸öbinary treeµÄÒ¶×ÓµÄ×îÉÙdepth
·Ö²ã±éÀú¼´¿É£¬ÂÔ¡£¡£
193. Integer to Roman number
CODE
194. ÓÐÒ»ÐÐanimal cages£¬Ã¿¸öcageµÄ¶¯ÎïµÄÓÃË®Á¿ÎªÊý×é,ÓÐÁ½¸öpipe¸øËùÓж¯Î﹩ˮ£¬pipe¸øµ±Ç°cageµÄcost ÊÇ Õâ¸öcage¶¯ÎïµÄÓÃË®Á¿£¬¸øÆäËûcageµÄ¶¯Î﹩ˮµÄcostÊÇ(distance to that cage)*ÄǸöcage¶¯ÎïµÄÓÃË®Á¿£¬ ÇóÁ½¸öpipe¹©Ë®µÄλÖÃʹcost×îС¡£
TO LEARN
195. ÎÊ°ÑÕûÊý·Ö³É sum of squareµÄ¾µäÎÊÌâ
TO LEARN£¬ÊýÂÛÌâ¡£¡£¡£
196. longest increase consecutive subsequence. e.g. 3, 2, 4, 5, 1, 6. Return {2, 4, 5}
CODE
197. ÓÃ1*2µÄ´Éש¸²¸Ç8*8µÄµØ°å£¬ÓжàÉÙÖÖ·½Ê½ÄØ£¿Èç¹ûÊÇN*MµÄµØ°åÄØ
ÖеÈÄѶȵÄDP£¬Óиö½âÌⱨ¸æ¼û£º
http://www.cnblogs.com/PureMilk/archive/2008/07/21/1247492.html
¹«Ê½µÄÂÛÎļû£º
http://arxiv.org/abs/math/0310326
198. Éú³ÉDyck word list
ÓëÉú³ÉËùÓкϷ¨µÄÀ¨ºÅ×éºÏÀàËÆ£¬¼û£º
http://en.wikipedia.org/wiki/Catalan_number
199. one integer array A with ascending order, for example 1 ,2 ,3,4, please generate another array B with any sum of any 3 different numbers picked from the A with ascending order, for example for 1,2,3,4, the result is (1+2+3),(1£«2£«4),(1£«3£«4),(2£«3£«4£©¡°
ÈýÖØÑ»·¼´¿É£¬´úÂëÂÔ¡£¡£
200. int array a[n] with all element 0<=a[i]<=1000,find the subarray with the largest sum that is <= max and output the starting and ending index of this subarray and the sum. If there is more than one such subarray, output the one with smallest starting index.
Ëã·¨£º
ÏÈÇó³öÀÛ¼ÓºÍcum[i] = a[0]+¡+a[i],´Óa[k]>max¿ªÊ¼£¬ÔÚÇ°Ãæ¶þ·Ö²éÕÒµÚÒ»¸öcum[l]>=(a[k]-max), Ö±µ½ÕÒµ½·¶Î§×î´óµÄrange. ¸´ÔÓ¶ÈO(NlogN)
201. given is an unsorted integer array, how to divide it into two subarrays, such that the averages of these two arrays are the same (or have minimum difference).what if those are positive in