摘要:
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)
浙公网安备 33010602011771号