上一页 1 2 3 4 5 6 ··· 8 下一页
摘要: A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message con... 阅读全文
posted @ 2014-07-05 11:03 Awy 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Divide two integers without using multiplication, division and mod operator.思路:不能使用乘法除法以及取模运算来计算两个数相除。主要做法就是,将因子不断乘2(向左移位即可实现),同时结果从1不断移位加倍,等到除数大于被除数一... 阅读全文
posted @ 2014-07-05 10:03 Awy 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of ... 阅读全文
posted @ 2014-07-04 11:01 Awy 阅读(204) 评论(0) 推荐(0) 编辑
摘要: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ... 阅读全文
posted @ 2014-07-04 09:16 Awy 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 适配器模式(Adapter),将一个类的接口转换成客户端希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。 适配器模式主要解决的问题,就简单来说,需要的东西就在面前,但却不能使用,而段时间有无法改造它,于是我们就想办法适配它。在软件开发中,也就是系统的... 阅读全文
posted @ 2014-07-04 00:06 Awy 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 状态模式(State),当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类。 状态模式主要解决的是当控制一个对象转换的条件表达式过于复杂时的情况。把状态的判断逻辑移到表示不同状态的一系列当中,可以把复杂的判断逻辑简化。当然,如果这个状态判断很简单,那就没必要用“状态模式”了... 阅读全文
posted @ 2014-07-03 21:15 Awy 阅读(252) 评论(0) 推荐(0) 编辑
摘要: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBA... 阅读全文
posted @ 2014-07-03 11:52 Awy 阅读(302) 评论(0) 推荐(0) 编辑
摘要: You are given a string,S, and a list of words,L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenati... 阅读全文
posted @ 2014-07-03 08:47 Awy 阅读(244) 评论(0) 推荐(0) 编辑
摘要: Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be changed... 阅读全文
posted @ 2014-07-02 12:21 Awy 阅读(240) 评论(0) 推荐(0) 编辑
摘要: Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be ... 阅读全文
posted @ 2014-07-01 23:54 Awy 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 抽象工厂模式(Abstract Factory),提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。 AbstractProductA和AbstractProductB是两个抽象产品,之所以抽象,是因为他们都有可能有两种不同的实现,而ProductA1、ProductA2和Pro... 阅读全文
posted @ 2014-07-01 16:25 Awy 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 观察者模式又叫发布-订阅(Publish/SubScribe)模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一主题对象。这个主题对象在状态发生变化时,会通知所有观察者对象,使他们能够自动更新自己。 #include #include using namespace std;/*Obse... 阅读全文
posted @ 2014-07-01 10:55 Awy 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(183) 评论(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 阅读(149) 评论(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 阅读(140) 评论(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 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 建造者模式(Builder),将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。 建造者模式结构图: Builder是为创建一个Product对象的各个部件指定的抽象接口;ConcreteBuilder是具体建造者,实现Builder接口,构建和装配各个部件;Produc... 阅读全文
posted @ 2014-06-29 09:39 Awy 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 外观模式(Facade),为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。 外观模式结构图:代码模板://四个子系统的类class SubSystemOne{public: void MethodOne() { cout MethodOne();... 阅读全文
posted @ 2014-06-29 00:23 Awy 阅读(302) 评论(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 阅读(163) 评论(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 阅读(168) 评论(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 阅读(164) 评论(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 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 模板方法模式,定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定的步骤。当我们要完成在某一细节层次一致的一个过程或一系列步骤,但其个别步骤在更详细的层次上的实现可能不同时,我们通常考虑用模板方法模式来处理。 Abstract... 阅读全文
posted @ 2014-06-27 08:46 Awy 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 原型模式(Prototype),用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。 下图是原型模式的结构图:原型模型其实就是一个对象再创建另外一个可定制的对象,而且不需任何创建的细节,我们来看看基本的原型模式代码。//原型类class Prototype{private: st... 阅读全文
posted @ 2014-06-26 23:34 Awy 阅读(221) 评论(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 阅读(131) 评论(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 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 代理模式(Proxy),为其他对象提供一种代理以控制这个对象的访问。 Subject类,定义了RealSubject和Proxy的公共接口,这样就在任何使用RealSubject的地方都可以使用Proxy。class Subject{public: virtual void Reque... 阅读全文
posted @ 2014-06-24 10:48 Awy 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 装饰模式(Decorator),动态地给一个对象添加一些额外的职责,就增加功能来说,装饰模式比生成子类更为灵活。 装饰模式结构图: Component是定义一个对象接口,可以给这些对象动态地添加职责。ConcreteComponent是定义了一个具体的对象,也可以给这个对象添加一些职责。Deco... 阅读全文
posted @ 2014-06-24 00:22 Awy 阅读(221) 评论(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 阅读(168) 评论(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 阅读(185) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 8 下一页