2013年9月11日

摘要: Flatten Binary Tree to Linked ListGiven 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 \ ... 阅读全文
posted @ 2013-09-11 22:13 似溦若岚 阅读(136) 评论(0) 推荐(0) 编辑
摘要: Populating Next Right Pointers in Each Node IIFollow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra space.For example,Given the following binary tree, 阅读全文
posted @ 2013-09-11 22:12 似溦若岚 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Populating Next Right Pointers in Each NodeGiven 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.In... 阅读全文
posted @ 2013-09-11 22:09 似溦若岚 阅读(138) 评论(0) 推荐(0) 编辑
摘要: Pascal's Triangle IIGiven 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?和118基本没区别吧…… 1 class Solution { 2 public: 3 vector getRow(int rowIndex) { 4 // Start typing your C/C++ ... 阅读全文
posted @ 2013-09-11 22:08 似溦若岚 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Pascal's TriangleGivennumRows, 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 > generate(int numRows) { 4 // Start typing your C/C++ solution below 5 ... 阅读全文
posted @ 2013-09-11 22:06 似溦若岚 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 vector> findLadders(string start, string end, unordered_set &dict) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector > result; 7 unordered_map > adj_set; 8 queue, int> > path; 9 ... 阅读全文
posted @ 2013-09-11 09:07 似溦若岚 阅读(141) 评论(0) 推荐(0) 编辑

导航