摘要: 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) 编辑