2014年4月2日

摘要: 【中心思想】开闭原则(Open Closed Principle,OCP):对扩展开放,对修改关闭。实现方式:里氏代换原则(Liskov Substitution Principle, LSP): 【抽象】任何基类可以出现的地方,子类一定可以出现(不可逆哦)。 我喜欢吃水果。此处的“水果”可以置换为“苹果”、“香蕉”、“草莓”……依赖倒置原则(Dependence Inversion Principle, DIP): 【抽象】依赖于抽象,不要依赖于具体。 水果可以“吃”的抽象行为,不依赖于苹果需要“洗过之后吃”、香蕉需要“剥皮吃”、草莓需要“摘掉蒂吃”……的具体行为。接口隔离原则(In... 阅读全文
posted @ 2014-04-02 13:54 似溦若岚 阅读(136) 评论(0) 推荐(0) 编辑

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) 编辑

2013年8月29日

摘要: Word LadderGiven two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog"dict=["h 阅读全文
posted @ 2013-08-29 22:22 似溦若岚 阅读(230) 评论(0) 推荐(0) 编辑
摘要: Valid PalindromeGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"isnota palindrome.Note:Have you consider that the string might be empty? This is a 阅读全文
posted @ 2013-08-29 10:30 似溦若岚 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Binary Tree Maximum Path SumGiven 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, 1 / \ 2 3Return6.二叉树后序历遍的变形。 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * ... 阅读全文
posted @ 2013-08-29 10:06 似溦若岚 阅读(174) 评论(0) 推荐(0) 编辑

导航