摘要: 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 阅读(172) 评论(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 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 面向对象的编程,并不是类越多越好,类的划分是为了封装,但分类的基础是抽象,具有相同属性和功能的对象的抽象集合才是类。 在说策略模式之前,我们想用简单工厂模式来实现商场收银程序#include using namespace std;//现金收费抽象类class CashSuper{public... 阅读全文
posted @ 2014-06-21 10:49 Awy 阅读(219) 评论(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 阅读(199) 评论(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 阅读(234) 评论(0) 推荐(0) 编辑
摘要: 工厂方法模式(Factory Method),定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使用一个类的实例化延迟到其子类。根据依赖倒转原则,我们把工厂类抽象出一个接口,这个接口只有一个方法,就是创建抽象产品的工厂方法。然后,所有的要生产具体类的工厂,就去实现这个接口,这样,一个... 阅读全文
posted @ 2014-06-19 00:47 Awy 阅读(367) 评论(0) 推荐(0) 编辑
摘要: 简单工厂模式没有抽象类,只有一个具体工厂类,所有产品的生产都由这个工厂类的对象来负责,如果这个工厂类中生产产品的方法被声明为静态的,那么连这个工厂对象也不是必须的了,直接使用工厂类名就可以调用生产方法。生产方法被声明为静态的,所以简单工厂模式也叫静态工厂模式。简单工厂模式并不是一个好的设计模式,... 阅读全文
posted @ 2014-06-18 23:27 Awy 阅读(192) 评论(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 阅读(165) 评论(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 阅读(219) 评论(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 阅读(201) 评论(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 阅读(226) 评论(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 阅读(176) 评论(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 阅读(142) 评论(0) 推荐(0) 编辑
摘要: Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniq... 阅读全文
posted @ 2014-05-28 00:23 Awy 阅读(6581) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of ... 阅读全文
posted @ 2014-05-27 16:09 Awy 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Implementint sqrt(int x).Compute and return the square root ofx.思路:二分查找法解决这道题class Solution {public: int sqrt(int x) { if(x1e-6) { ... 阅读全文
posted @ 2014-05-24 20:02 Awy 阅读(232) 评论(0) 推荐(0) 编辑
摘要: Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.思路:这道... 阅读全文
posted @ 2014-05-24 17:11 Awy 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru... 阅读全文
posted @ 2014-05-23 11:15 Awy 阅读(105) 评论(0) 推荐(0) 编辑
摘要: Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation... 阅读全文
posted @ 2014-05-23 09:41 Awy 阅读(327) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2014-05-21 00:12 Awy 阅读(170) 评论(0) 推荐(0) 编辑
摘要: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana... 阅读全文
posted @ 2014-05-20 17:50 Awy 阅读(155) 评论(0) 推荐(0) 编辑
摘要: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo... 阅读全文
posted @ 2014-05-15 13:56 Awy 阅读(137) 评论(0) 推荐(0) 编辑
摘要: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ... 阅读全文
posted @ 2014-05-15 12:11 Awy 阅读(153) 评论(0) 推荐(0) 编辑
摘要: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文
posted @ 2014-05-13 11:06 Awy 阅读(208) 评论(0) 推荐(0) 编辑
摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ... 阅读全文
posted @ 2014-05-13 09:53 Awy 阅读(221) 评论(0) 推荐(0) 编辑
摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路:回文构词法是由颠倒字母顺序而来的单词。主要的特点就是字母个数和种类都... 阅读全文
posted @ 2014-05-12 08:44 Awy 阅读(125) 评论(0) 推荐(0) 编辑
摘要: The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo... 阅读全文
posted @ 2014-05-12 07:47 Awy 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:合并k个有序链表为一个有序链表。我们可以用先合并两个链表的方法,然后逐个遍历链表数组,与上一个合并结束... 阅读全文
posted @ 2014-05-10 10:21 Awy 阅读(113) 评论(0) 推荐(0) 编辑
摘要: Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the orig... 阅读全文
posted @ 2014-05-10 09:20 Awy 阅读(106) 评论(0) 推荐(0) 编辑
摘要: There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[... 阅读全文
posted @ 2014-05-07 09:20 Awy 阅读(236) 评论(0) 推荐(0) 编辑