上一页 1 ··· 7 8 9 10 11
摘要: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ... 阅读全文
posted @ 2013-02-14 18:59 一只会思考的猪 阅读(140) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x... 阅读全文
posted @ 2013-02-14 18:46 一只会思考的猪 阅读(109) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x... 阅读全文
posted @ 2013-02-14 18:43 一只会思考的猪 阅读(214) 评论(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?class Solution {public: vector<int> getRow(int rowIndex) { // Start typing your C/C++ solution below // DO NOT write i... 阅读全文
posted @ 2013-02-13 19:49 一只会思考的猪 阅读(134) 评论(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]]class Solution {public: vector > generate(int numRows) { // Start typing your C/C++ solution below // DO NOT write int main() functi... 阅读全文
posted @ 2013-02-13 19:26 一只会思考的猪 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 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 \ 6思路:三种写法 1) 维持一个全局变量作为Prev来进行th... 阅读全文
posted @ 2013-02-13 14:28 一只会思考的猪 阅读(174) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree,For example:Given the below binary tree, 1 / \ 2 3Return6./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *lef... 阅读全文
posted @ 2013-02-13 11:03 一只会思考的猪 阅读(176) 评论(0) 推荐(0) 编辑
摘要: to be proved, to be continued 阅读全文
posted @ 2012-12-25 18:46 一只会思考的猪 阅读(105) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11