基础不牢,地动山摇!

设计模式之二十三:解释器模式

解释器模式: 给定一个语言,定义了它的文法的一种表示,并定义了一个解释器,这个解释器使用该表示来解释语言中的句子。 Given a language, define a representation for its grammar along with an interpreter that ...

2015-06-30 16:28:46

阅读数:743

评论数:0

设计模式之二十二:享元模式(FlyWeight)

享元模式: 使用共享技术有效地支持大量细粒度的对象。 Use sharing to support large numbers of fine-grained objects efficiently. 这个设计模式和它的名字一样核心是为了共享代码。UML图: 主要包括: FlyWeight...

2015-06-30 10:37:44

阅读数:927

评论数:0

LeetCode122:Best Time to Buy and Sell Stock II

Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may comple...

2015-06-30 09:01:15

阅读数:699

评论数:0

LeetCode15:3Sum

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...

2015-06-29 17:10:28

阅读数:538

评论数:0

设计模式之二十一:中介者模式(Mediator)

中介者模式:定义了一个对象,用来封装一系列对象的交互。中介者模式通过使对象之间不必显式引用降低了对象之间的耦合,并且允许你独立改变它们之间的交互。中介者模式就是将对象之间的交互封装在了一个独立的对象中,这个独立的对象用来控制对象之间的交互行为,所以这个对象还是蛮复杂的。UML类图: 主要包括: ...

2015-06-28 13:25:36

阅读数:1065

评论数:0

设计模式之二十:责任链模式(Chain of Responsibility)

感觉这个设计模式和组合模式一样是一种很巧妙的设计模式,在需要使用它的地方如果不使用这种设计模式代码会变的很复杂,但是这种设计模式的基本原理又是很简单的。责任链模式: 通过使多个对象都有机会来处理请求的方式避免了请求的发送者和接收者之间的耦合。将接收者组织成链式的结构这样可以将请求沿着这条链进行传...

2015-06-27 16:06:57

阅读数:719

评论数:0

设计模式之十九:命令模式(Command)

命令模式:将一个请求封装成一个对象,从而允许用不同的请求参数化客户,对请求进行排序或记录日志,并且支持撤销操作。UML图: 主要包括: Command:声明了一个操作的接口 ConcreteCommand:绑定了一个Receiver和一个行为,通过相关联的Receiver对象实现了了execut...

2015-06-27 15:02:39

阅读数:721

评论数:0

LeetCode228:Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”]....

2015-06-26 16:08:43

阅读数:683

评论数:0

LeetCode204:Count Primes

Description:Count the number of prime numbers less than a non-negative number, n.计算小于n的非负整数中素数的个数。 素数又称质数,是指只能被1和它自身相除的自然数。需要注意的是1既不是素数也不是合数。2是最小的素数...

2015-06-25 17:00:20

阅读数:607

评论数:0

LeetCode95:Unique Binary Search Trees II

Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example, Given n = 3, your program should return all...

2015-06-25 00:11:41

阅读数:1407

评论数:0

设计模式之十八:桥接模式(Bridge)

桥接模式: 将抽象部分和它的实现部分相分离开来,以使它们可以单独地变化。UML图: 主要包括: Abstraction:定义了抽象部分的接口,操作一个实现部分对象的引用。 RefinedAbstraction:继承自抽象部分的类。 Implementor:实现部分的接口。 ConcreteIm...

2015-06-24 22:38:16

阅读数:793

评论数:0

LeetCode96:Unique Binary Search Trees

Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 uniqu...

2015-06-24 15:56:10

阅读数:2635

评论数:0

LeetCode120:Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fo...

2015-06-24 13:13:09

阅读数:640

评论数:0

LeetCode226:Invert Binary Tree

nvert a binary tree. Trivia: This problem was inspired by this original tweet by Max Howell: Google: 90% of our engineers use the software you wro...

2015-06-23 23:47:35

阅读数:890

评论数:0

LeetCode64:Minimum Path Sum

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path....

2015-06-23 23:11:21

阅读数:616

评论数:0

LeetCode152:Maximum Product Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], ...

2015-06-23 22:19:47

阅读数:575

评论数:0

LeetCode77:Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 … n.For example, If n = 4 and k = 2, a solution is:[ [2,4], ...

2015-06-23 21:45:27

阅读数:735

评论数:0

LeetCode53:Maximum Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,...

2015-06-23 11:01:49

阅读数:517

评论数:0

LeetCode221:Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following m...

2015-06-18 22:53:12

阅读数:2309

评论数:0

LeetCode91:Decode Ways

A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given ...

2015-06-18 18:17:39

阅读数:2352

评论数:0

提示
确定要删除当前文章?
取消 删除