上一页 1 ··· 3 4 5 6 7 8 9 10 11 下一页

2013年5月25日

摘要: Problem:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) must be in non-descending order. (ie,a?b?c)The solution set must not contain duplicate triplets. For example, given... 阅读全文
posted @ 2013-05-25 10:03 freeneng 阅读(134) 评论(0) 推荐(0) 编辑
摘要: Problem:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.Analysis:In roman number system, there are 3 special cases1. 900 or 4002. 90 or 403. 9 or 4Process the integer number digit by digit, if it's 9 or 4, process it separately. Then if i 阅读全文
posted @ 2013-05-25 09:40 freeneng 阅读(117) 评论(0) 推荐(0) 编辑

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 阅读(123) 评论(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 阅读(145) 评论(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 阅读(108) 评论(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 阅读(111) 评论(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 阅读(161) 评论(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 阅读(149) 评论(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 阅读(140) 评论(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 阅读(196) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 下一页

导航