上一页 1 2 3 4 5 6 ··· 10 下一页
摘要: 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.---public class Solution { public int maxProfit(int[] pr... 阅读全文
posted @ 2013-09-26 09:07 LEDYC 阅读(146) 评论(0) 推荐(0)
摘要: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11(i.e.,2+3+5+1= 11).Note:Bonus point if you are a... 阅读全文
posted @ 2013-09-26 09:02 LEDYC 阅读(123) 评论(0) 推荐(0)
摘要: 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?---public class Solution { public ArrayList getRow(int rowIndex) { ArrayList rst = new ArrayList(); for (int ... 阅读全文
posted @ 2013-09-26 08:44 LEDYC 阅读(145) 评论(0) 推荐(0)
摘要: 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]]---public class Solution { public ArrayList> generate(int numRows) { ArrayList> rst = new ArrayList>(); int i=0, ... 阅读全文
posted @ 2013-09-26 04:44 LEDYC 阅读(165) 评论(0) 推荐(0)
摘要: Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra space.For example,Given the following binary tree, 1 / \ 2 3 / \ \ 4 5 ... 阅读全文
posted @ 2013-09-26 03:52 LEDYC 阅读(193) 评论(0) 推荐(0)
摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL.N... 阅读全文
posted @ 2013-09-26 03:41 LEDYC 阅读(176) 评论(0) 推荐(0)
摘要: You are given a string,S, and a list of words,L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.For example, given:S:"barfoothefoobarman"L:["foo", " 阅读全文
posted @ 2013-09-23 07:55 LEDYC 阅读(261) 评论(0) 推荐(1)
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory.He 阅读全文
posted @ 2013-09-23 05:53 LEDYC 阅读(167) 评论(0) 推荐(1)
摘要: Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,"ACE" 阅读全文
posted @ 2013-09-23 04:34 LEDYC 阅读(250) 评论(0) 推荐(1)
摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6click to show hints.---/** * D... 阅读全文
posted @ 2013-09-23 04:17 LEDYC 阅读(143) 评论(0) 推荐(1)
上一页 1 2 3 4 5 6 ··· 10 下一页