06 2014 档案

摘要:There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requi... 阅读全文
posted @ 2014-06-30 12:55 Awy 阅读(193) 评论(0) 推荐(0)
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2014-06-30 10:47 Awy 阅读(155) 评论(0) 推荐(0)
摘要:Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="... 阅读全文
posted @ 2014-06-29 17:22 Awy 阅读(154) 评论(0) 推荐(0)
摘要:Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest... 阅读全文
posted @ 2014-06-29 15:03 Awy 阅读(113) 评论(0) 推荐(0)
摘要:建造者模式(Builder),将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。 建造者模式结构图: Builder是为创建一个Product对象的各个部件指定的抽象接口;ConcreteBuilder是具体建造者,实现Builder接口,构建和装配各个部件;Produc... 阅读全文
posted @ 2014-06-29 09:39 Awy 阅读(214) 评论(0) 推荐(0)
摘要:外观模式(Facade),为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。 外观模式结构图:代码模板://四个子系统的类class SubSystemOne{public: void MethodOne() { cout MethodOne();... 阅读全文
posted @ 2014-06-29 00:23 Awy 阅读(325) 评论(0) 推荐(0)
摘要:Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner cas... 阅读全文
posted @ 2014-06-28 23:14 Awy 阅读(174) 评论(0) 推荐(0)
摘要:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjace... 阅读全文
posted @ 2014-06-28 18:01 Awy 阅读(181) 评论(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, 1 ... 阅读全文
posted @ 2014-06-27 15:48 Awy 阅读(175) 评论(0) 推荐(0)
摘要:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.... 阅读全文
posted @ 2014-06-27 11:30 Awy 阅读(267) 评论(0) 推荐(0)
摘要:模板方法模式,定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定的步骤。当我们要完成在某一细节层次一致的一个过程或一系列步骤,但其个别步骤在更详细的层次上的实现可能不同时,我们通常考虑用模板方法模式来处理。 Abstract... 阅读全文
posted @ 2014-06-27 08:46 Awy 阅读(177) 评论(0) 推荐(0)
摘要:原型模式(Prototype),用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。 下图是原型模式的结构图:原型模型其实就是一个对象再创建另外一个可定制的对象,而且不需任何创建的细节,我们来看看基本的原型模式代码。//原型类class Prototype{private: st... 阅读全文
posted @ 2014-06-26 23:34 Awy 阅读(236) 评论(0) 推荐(0)
摘要:Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For exam... 阅读全文
posted @ 2014-06-25 12:30 Awy 阅读(142) 评论(0) 推荐(0)
摘要:Sort a linked list in O(n log n) time using constant space complexity.思路:使用O(nlogn)时间复杂度和常数空间复杂度,我们想到可以用归并排序。1)找到链表中间位置2)将两个链表按序合并链表3)对所给链表进行整体的归并排序/*... 阅读全文
posted @ 2014-06-25 10:40 Awy 阅读(162) 评论(0) 推荐(0)
摘要:代理模式(Proxy),为其他对象提供一种代理以控制这个对象的访问。 Subject类,定义了RealSubject和Proxy的公共接口,这样就在任何使用RealSubject的地方都可以使用Proxy。class Subject{public: virtual void Reque... 阅读全文
posted @ 2014-06-24 10:48 Awy 阅读(183) 评论(0) 推荐(0)
摘要:装饰模式(Decorator),动态地给一个对象添加一些额外的职责,就增加功能来说,装饰模式比生成子类更为灵活。 装饰模式结构图: Component是定义一个对象接口,可以给这些对象动态地添加职责。ConcreteComponent是定义了一个具体的对象,也可以给这个对象添加一些职责。Deco... 阅读全文
posted @ 2014-06-24 00:22 Awy 阅读(243) 评论(0) 推荐(0)
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.2... 阅读全文
posted @ 2014-06-23 16:27 Awy 阅读(176) 评论(0) 推荐(0)
摘要:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially... 阅读全文
posted @ 2014-06-23 09:43 Awy 阅读(195) 评论(0) 推荐(0)
摘要:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-nega... 阅读全文
posted @ 2014-06-21 21:54 Awy 阅读(181) 评论(0) 推荐(0)
摘要:Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].思路:这道题就是把区间数重合... 阅读全文
posted @ 2014-06-21 18:09 Awy 阅读(168) 评论(0) 推荐(0)
摘要:单一职责原则(SRP),就一个类而言,应该仅有一个引起它变化的原则。 我们在做编程的时候,很自然地就会给一个类加各种各样的功能,比如我们写一个窗体应用程序,一般会生成一个Form1这样的类,于是我们就把各种各样的代码,我们像某种商业运算的算法呀,像数据库访问的SQL语句呀什么的都写到这样的类当中,... 阅读全文
posted @ 2014-06-21 12:01 Awy
摘要:面向对象的编程,并不是类越多越好,类的划分是为了封装,但分类的基础是抽象,具有相同属性和功能的对象的抽象集合才是类。 在说策略模式之前,我们想用简单工厂模式来实现商场收银程序#include using namespace std;//现金收费抽象类class CashSuper{public... 阅读全文
posted @ 2014-06-21 10:49 Awy 阅读(229) 评论(0) 推荐(0)
摘要:Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such possibl... 阅读全文
posted @ 2014-06-20 10:49 Awy 阅读(209) 评论(0) 推荐(0)
摘要:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl... 阅读全文
posted @ 2014-06-19 23:16 Awy 阅读(243) 评论(0) 推荐(0)
摘要:工厂方法模式(Factory Method),定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使用一个类的实例化延迟到其子类。根据依赖倒转原则,我们把工厂类抽象出一个接口,这个接口只有一个方法,就是创建抽象产品的工厂方法。然后,所有的要生产具体类的工厂,就去实现这个接口,这样,一个... 阅读全文
posted @ 2014-06-19 00:47 Awy 阅读(380) 评论(0) 推荐(0)
摘要:简单工厂模式没有抽象类,只有一个具体工厂类,所有产品的生产都由这个工厂类的对象来负责,如果这个工厂类中生产产品的方法被声明为静态的,那么连这个工厂对象也不是必须的了,直接使用工厂类名就可以调用生产方法。生产方法被声明为静态的,所以简单工厂模式也叫静态工厂模式。简单工厂模式并不是一个好的设计模式,... 阅读全文
posted @ 2014-06-18 23:27 Awy 阅读(205) 评论(0) 推荐(0)
摘要:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest pa... 阅读全文
posted @ 2014-06-18 10:14 Awy 阅读(172) 评论(0) 推荐(0)
摘要:The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie... 阅读全文
posted @ 2014-06-18 09:04 Awy 阅读(230) 评论(0) 推荐(0)
摘要:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there will be on... 阅读全文
posted @ 2014-06-16 11:55 Awy 阅读(204) 评论(0) 推荐(0)
摘要:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.思路:这是一道字符串匹配的函数,就是找出needle... 阅读全文
posted @ 2014-06-16 00:44 Awy 阅读(234) 评论(0) 推荐(0)
摘要:Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histog... 阅读全文
posted @ 2014-06-01 13:30 Awy 阅读(188) 评论(0) 推荐(0)
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.思路:本题给你包含0和1的矩阵,让你找出包含1的最大矩阵,并返回其... 阅读全文
posted @ 2014-06-01 11:44 Awy 阅读(150) 评论(0) 推荐(0)