2014年3月19日

Best Time to Buy and Sell Stock II

摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at 阅读全文

posted @ 2014-03-19 16:47 pengyu2003 阅读(104) 评论(0) 推荐(0)

Triangle

摘要: 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 @ 2014-03-19 16:19 pengyu2003 阅读(168) 评论(0) 推荐(0)

Populating Next Right Pointers in Each Node

摘要: 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 @ 2014-03-19 16:02 pengyu2003 阅读(189) 评论(0) 推荐(0)

Flatten Binary Tree to Linked List

摘要: 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.刚开始想偷懒想把几个... 阅读全文

posted @ 2014-03-19 15:27 pengyu2003 阅读(109) 评论(0) 推荐(0)

Binary Tree Level Order Traversal II

摘要: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]先查看有... 阅读全文

posted @ 2014-03-19 14:58 pengyu2003 阅读(101) 评论(0) 推荐(0)

导航