2013年5月24日

摘要: Problem:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.No 阅读全文
posted @ 2013-05-24 13:30 freeneng 阅读(131) 评论(0) 推荐(0)
摘要: Problem:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I GY I RAnd then read line by line:"PAHNAPLSIIGYIR"Write the code that will take a st 阅读全文
posted @ 2013-05-24 12:29 freeneng 阅读(155) 评论(0) 推荐(0)
摘要: Problem:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the lengt 阅读全文
posted @ 2013-05-24 11:41 freeneng 阅读(116) 评论(0) 推荐(0)
摘要: Problem:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)Output:7 -> 0 -> 8Analysis:Simp 阅读全文
posted @ 2013-05-24 10:27 freeneng 阅读(117) 评论(0) 推荐(0)
摘要: Problem:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-leaf path1->2represents the nu 阅读全文
posted @ 2013-05-24 10:09 freeneng 阅读(170) 评论(0) 推荐(0)
摘要: Problem:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"isnota palindrome.Note:Have you consider that the string might be empty? This is a good que 阅读全文
posted @ 2013-05-24 09:26 freeneng 阅读(159) 评论(0) 推荐(0)
摘要: Probelm:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.Analysis:There's obviously a O(n^2) algorithm: 阅读全文
posted @ 2013-05-24 06:52 freeneng 阅读(146) 评论(0) 推荐(0)
摘要: Problem:Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(k) extra space?Analysis:The direct way to solve the problem is to use the formula: C(i, k) = k! / (i! * (k-i)!). But it will exceed the in 阅读全文
posted @ 2013-05-24 06:27 freeneng 阅读(201) 评论(0) 推荐(0)
摘要: Problem:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Analysis:There two ways to solve the problem, either compute each row element separately or use inductive method.The latter cost much more le... 阅读全文
posted @ 2013-05-24 05:39 freeneng 阅读(203) 评论(0) 推荐(0)
摘要: Problem:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1return[ [5... 阅读全文
posted @ 2013-05-24 05:26 freeneng 阅读(181) 评论(0) 推荐(0)
摘要: Problem:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence.Note: The sequence 阅读全文
posted @ 2013-05-24 05:03 freeneng 阅读(312) 评论(0) 推荐(0)

导航