摘要:
Same with inorder.1. recursive: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeN... 阅读全文
posted @ 2015-03-18 08:28
keepshuatishuati
阅读(153)
评论(0)
推荐(0)
摘要:
Still 3 methods:Same with inorder, but post order is a little different. We need to treat it as reverse result of preorder.So we go to right branch fi... 阅读全文
posted @ 2015-03-18 08:24
keepshuatishuati
阅读(194)
评论(0)
推荐(0)
摘要:
Use lMax get the maximum value of a sub SINGLE branch (left branch or right branch or just current node).Use gMax get the maximum value of the whole s... 阅读全文
posted @ 2015-03-18 08:06
keepshuatishuati
阅读(119)
评论(0)
推荐(0)
摘要:
This question is almost same as the previous one.I just use a stack (another vector) of vector to store the level result. Then reverse it. 1 /** 2 * ... 阅读全文
posted @ 2015-03-18 07:56
keepshuatishuati
阅读(113)
评论(0)
推荐(0)
摘要:
Basic question. Use a queue to store Node, use two numbers to record current level node numbers and next level node numbers. 1 /** 2 * Definition for... 阅读全文
posted @ 2015-03-18 07:44
keepshuatishuati
阅读(109)
评论(0)
推荐(0)
摘要:
There are three methods to do it:1. recursive(use memory stack): (Time O(n), Space O(logn) 1 /** 2 * Definition for binary tree 3 * struct TreeNode ... 阅读全文
posted @ 2015-03-18 07:39
keepshuatishuati
阅读(151)
评论(0)
推荐(0)
摘要:
It is similar to use stack for BST inorder traversal.So do the same thing :1. Get stack to store right branchs(include current node).2. When you pop t... 阅读全文
posted @ 2015-03-18 07:31
keepshuatishuati
阅读(123)
评论(0)
推荐(0)
摘要:
This is combination of II and III.1. when k >= length, it is totally II.2. when k localMax[j] = max(localMax[j] + diff, globalMax[j-1] + max(0, diff... 阅读全文
posted @ 2015-03-18 07:27
keepshuatishuati
阅读(231)
评论(0)
推荐(0)
摘要:
III is a kind of I. But it require 2 maximum value. So scan from begin and scan from end to record the maximum value for currrent index.Then scan the ... 阅读全文
posted @ 2015-03-18 07:18
keepshuatishuati
阅读(141)
评论(0)
推荐(0)
摘要:
This is simple, use greedy algorithm will solve the problem. 1 class Solution { 2 public: 3 int maxProfit(vector &prices) { 4 int len = pr... 阅读全文
posted @ 2015-03-18 07:15
keepshuatishuati
阅读(120)
评论(0)
推荐(0)
浙公网安备 33010602011771号