摘要: 219. Contains Duplicate II Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that 阅读全文
posted @ 2017-02-05 16:30 花椰菜菜菜菜 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 它定义了一系列的算法,并将每个算法封装起来,而且使他们还可以相互替换。策略模式让算法的变化不会影响到使用算法的客户。 优点: 1)简化了单元测试,因为每个算法都有自己的类,可以通过自己的接口单独测试。 2)避免程序中使用多重条件转移语句,使系统更灵活,并易于扩展。 3)遵守大部分GRASP原则和常用 阅读全文
posted @ 2017-01-21 21:28 花椰菜菜菜菜 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 以计算器程序为例:只需输入运算符号,程序就实例化出合适的对象。通过多态,返回父类的方式实现了计算器的结果。 1)静态工厂方法统一管理对象的创建。 静态工厂方法通过传入的参数判断决定创建哪一个产品的实例,封装了对象的创建,客户端只管消费,实现了对责任(模块)的分割。 2)静态工厂方法推迟了产品的实例化 阅读全文
posted @ 2017-01-21 18:56 花椰菜菜菜菜 阅读(343) 评论(0) 推荐(0) 编辑
摘要: 217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears a 阅读全文
posted @ 2016-12-18 20:50 花椰菜菜菜菜 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 206. Reverse Linked List Reverse a singly linked list. 翻转一个单链表。 代码如下: 阅读全文
posted @ 2016-11-14 16:02 花椰菜菜菜菜 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 205. Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced 阅读全文
posted @ 2016-11-14 10:58 花椰菜菜菜菜 阅读(306) 评论(0) 推荐(0) 编辑
摘要: 202. Happy Number Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with a 阅读全文
posted @ 2016-11-09 11:41 花椰菜菜菜菜 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 198. House Robber You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only cons 阅读全文
posted @ 2016-11-09 11:05 花椰菜菜菜菜 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 191. Number of 1 Bits Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). Fo 阅读全文
posted @ 2016-11-09 10:13 花椰菜菜菜菜 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 0000001010010100000111 阅读全文
posted @ 2016-11-09 10:05 花椰菜菜菜菜 阅读(102) 评论(0) 推荐(0) 编辑