摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:Bonus points if you could solve it both recursively and iterati... 阅读全文
posted @ 2013-04-30 13:39 caijinlong 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 bool isSameTree(TreeNode *p, TreeNode *q) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if (p == NULL && q == NULL) 7 return true; 8 if ((p == NULL && q != NULL) || (p != NULL && q... 阅读全文
posted @ 2013-04-30 10:53 caijinlong 阅读(116) 评论(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? 1 class Solution { 2 public: 3 vector<int> getRow(int rowIndex) { 4 vector<int> res; 5 if(rowIndex < 0) 6 ... 阅读全文
posted @ 2013-04-30 10:44 caijinlong 阅读(117) 评论(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]] 1 class Solution { 2 public: 3 vector<vector<int> > generate(int numRows) { 4 // Start typing your C/C++ solution below 5 // DO ... 阅读全文
posted @ 2013-04-30 10:16 caijinlong 阅读(120) 评论(0) 推荐(0) 编辑