06 2015 档案

摘要:Description:Implement int sqrt(int x).Compute and return the square root of x.好好学习数学还是非常有用的,牛顿迭代法 求解。 计算x2= n的解,令f(x)=x2-n,相当于求解f(x)=0的解,如左图所示。 首先取x0,... 阅读全文
posted @ 2015-06-29 00:10 Pickle 阅读(174) 评论(0) 推荐(0) 编辑
摘要:Description:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will r... 阅读全文
posted @ 2015-06-28 23:54 Pickle 阅读(203) 评论(0) 推荐(0) 编辑
摘要:Description:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must b... 阅读全文
posted @ 2015-06-28 00:47 Pickle 阅读(191) 评论(0) 推荐(0) 编辑
摘要:超时了,只能先这么干了。return Math.pow(x, n); 阅读全文
posted @ 2015-06-28 00:16 Pickle 阅读(135) 评论(0) 推荐(0) 编辑
摘要:Description: Given an array of integers, every element appears three times except for one. Find that single one.只有一个出现一次的数字,其他的都出现了3次,找出出现一次的那个数字。pub... 阅读全文
posted @ 2015-06-27 23:36 Pickle 阅读(143) 评论(0) 推荐(0) 编辑
摘要:Description: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",... 阅读全文
posted @ 2015-06-27 00:08 Pickle 阅读(213) 评论(0) 推荐(0) 编辑
摘要:Description:Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the large... 阅读全文
posted @ 2015-06-26 00:42 Pickle 阅读(194) 评论(0) 推荐(0) 编辑
摘要:Description:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct eleme... 阅读全文
posted @ 2015-06-25 22:45 Pickle 阅读(191) 评论(0) 推荐(0) 编辑
摘要:Description:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the... 阅读全文
posted @ 2015-06-25 00:18 Pickle 阅读(222) 评论(0) 推荐(0) 编辑
摘要:Description:Given an array of integers, every element appears twice except for one. Find that single one.找出只出现一次的数。public class Solution { public i... 阅读全文
posted @ 2015-06-24 23:06 Pickle 阅读(179) 评论(0) 推荐(0) 编辑
摘要:Description:https://leetcode.com/problems/rectangle-area/public class Solution { public int computeArea(int A, int B, int C, int D, int E, int F, i... 阅读全文
posted @ 2015-06-24 00:50 Pickle 阅读(221) 评论(0) 推荐(0) 编辑
摘要:Description:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any posi... 阅读全文
posted @ 2015-06-24 00:33 Pickle 阅读(183) 评论(0) 推荐(0) 编辑
摘要:Description:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint... 阅读全文
posted @ 2015-06-23 23:57 Pickle 阅读(190) 评论(0) 推荐(0) 编辑
摘要:Description:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A... 阅读全文
posted @ 2015-06-19 23:11 Pickle 阅读(181) 评论(0) 推荐(0) 编辑
摘要:Description:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, "A man, a plan, ... 阅读全文
posted @ 2015-06-19 22:48 Pickle 阅读(168) 评论(0) 推荐(0) 编辑
摘要:Description:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3, Return [1,3,3,1].public class Solution { public... 阅读全文
posted @ 2015-06-19 21:53 Pickle 阅读(199) 评论(0) 推荐(0) 编辑
摘要:Description:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3... 阅读全文
posted @ 2015-06-19 21:42 Pickle 阅读(174) 评论(0) 推荐(0) 编辑
摘要:Description:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in whi... 阅读全文
posted @ 2015-06-19 11:57 Pickle 阅读(178) 评论(0) 推荐(0) 编辑
摘要:Description:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop(... 阅读全文
posted @ 2015-06-19 00:04 Pickle 阅读(203) 评论(0) 推荐(0) 编辑
摘要:Description:The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11. 1... 阅读全文
posted @ 2015-06-18 19:38 Pickle 阅读(179) 评论(0) 推荐(0) 编辑
摘要:Description:Invert a binary tree. 4 / \ 2 7/ \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1递归invert就好了。/** * Definition for a binary tree ... 阅读全文
posted @ 2015-06-16 23:58 Pickle 阅读(209) 评论(0) 推荐(0) 编辑
摘要:Description: Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i... 阅读全文
posted @ 2015-06-16 23:37 Pickle 阅读(266) 评论(0) 推荐(0) 编辑
摘要:桥接模式核心:处理多层继承结构,处理多维度变化的场景。将各个维度设计成独立的继承结构,使各个维度可以独立的扩展在抽象层建立关联。 桥接模式特点: 桥接模式可以取代多层继承的方案。多层继承违背了单一职责原则。复用性较差。类的个数也非常多。桥接模式可以极大的减少子类的个数,从而降低管理和维护的成本。 桥... 阅读全文
posted @ 2015-06-04 23:21 Pickle 阅读(901) 评论(0) 推荐(0) 编辑
摘要:责任链模式:将能够处理同一类请求的对象连成一条链所提交的请求沿着链传递,链上的对象逐个判断是否有能力处理该请求, 如果能则处理,如果不能则传递给链上的下一个对象。优点:将请求者和发送者解耦简化对象的处理过程可以通过改变链中的成员或成员的顺序来动态的新增或则删除责任。缺点:不能保证请求一定会执行,可能... 阅读全文
posted @ 2015-06-04 00:27 Pickle 阅读(2897) 评论(0) 推荐(0) 编辑
摘要:代理模式:核心作用:通过代理控制对对象的访问,可以详细访问某个对象的方法,在调用这个方法前置处理,调用这个方法后做后置处理。 抽象角色:定义角色代理和真实角色的公共对外方法。 真实角色:实现抽象角色,定义真实角色所需要的实现的业务逻辑,供代理角色调用。 关注真正的业务逻辑!代理角色:实现抽象角色,是... 阅读全文
posted @ 2015-06-03 23:08 Pickle 阅读(954) 评论(0) 推荐(0) 编辑
摘要:享元模式: 场景:内存属于稀缺资源,如果有很多个完全相同或相似的对象,我们可以通过享元模式来节省内存。 核心:享元模式以共享的方式高效地支持大量细粒度对象的重用。 享元对象能做到共享的关键字是区分了内部状态和外部状态。 内部状态:可以共享,不会随着环境变化而改变。 外部状态:不可以共享,会随着... 阅读全文
posted @ 2015-06-03 17:57 Pickle 阅读(445) 评论(0) 推荐(0) 编辑
摘要:中介者模式:如果一个系统中对象之间的联系呈现为网状结构,对象之间存在大量的多对多关系,将导致关系及其复杂,这些对象称为“同事对象”, 我们可以引入一个中介者对象使各个同时对象只跟中介者对象打交道。将复杂的网络结构化解为如下的星形结构。使用中介者模式来 集中相关对象之间复杂的沟通和控制方式。优点: 通... 阅读全文
posted @ 2015-06-02 15:57 Pickle 阅读(826) 评论(1) 推荐(0) 编辑
摘要://求一个整数的二进制串中1的个数public int hammingWeight(int n) { String b_str = Integer.toBinaryString(n); int b_count = 0; for(int i=0; i<b_str.length(... 阅读全文
posted @ 2015-06-01 23:54 Pickle 阅读(201) 评论(0) 推荐(0) 编辑
摘要:状态模式:用于解决系统中复杂对象的状态转换以及不同状态下行为的封装问题。 结构:Context环境类:环境类中维护一个State对象,它定义了当前的状态 。 State:状态接口 ConcreteState: 具体的状态类,封装了每一个具体类的对应行为。 应用场景: 线程对象各个状态的切换 店房间... 阅读全文
posted @ 2015-06-01 17:23 Pickle 阅读(1496) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示