自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(23)
  • 收藏
  • 关注

原创 [leetcode]Regular Expression Matching

Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire inp...

2013-10-23 23:06:35 107

原创 [leetcode]Symmetric Tree

//判断二叉树是否镜面对称,即判断左右子树是否互为镜像public class Solution { public boolean isSymmetric(TreeNode root) { // Note: The Solution object is instantiated only once and is reused by each test case....

2013-10-23 11:06:07 107

原创 矩阵旋转

 没什么高端算法..注意下标,思维清晰就可以了。 //矩阵顺时针旋转90度,如果是in-place,则矩阵只能为方阵//如果可以利用其它存储空间,则矩阵可以是m*n的,转换之后为n*m的//i'(转换后行) = j(原列); j'(转换后列)= m-1-i(原行);//我们这里写就地逆置的public class ClockWiseTransferMatrixIn...

2013-10-22 19:59:37 132

原创 [leetcode]Candy

Candy AC Rate: 1460/9941 There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requi...

2013-10-15 11:54:41 81

原创 [leetcode]Clone Graph

看到克隆图,自然想到遍历所有节点的算法,DFS/BFS改造下就可以了本题中map用来保存已复制的节点(关系没有复制),同时也起到一个标记节点已访问过的作用。 /** * Definition for undirected graph. * class UndirectedGraphNode { * int label; * ArrayList<Un...

2013-10-14 17:10:38 85

原创 [leetcode] Copy List with Random Pointer

剑指offer上面的题目代码: public RandomListNode copyRandomList(RandomListNode head) { // Note: The Solution object is instantiated only once and is reused by each test case. cloneNode(...

2013-10-14 16:28:06 67

原创 [leetcode]Container With Most Water 和Largest Rectangle in Histogram

这两题看起来有点像,但是实际上是完全不一样的,区别在于:The "Container With Most Water" solution will allow the water to rise above intermediate positions. With the "largest rectangle" problem, the rectangle cannot rise abov...

2013-10-13 22:59:27 103

原创 [leetcode]Search in Rotated Sorted Array

放了个国庆,最近几天效率低下,我忏悔-。-Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found...

2013-10-08 23:18:21 75

原创 [转载]程序员面试100题之十六:二叉树中两个节点的最近公共父节点

本文转载自 http://blog.csdn.net/hackbuteer1/article/details/8022138 这个问题可以分为三种情况来考虑:情况一:root未知,但是每个节点都有parent指针此时可以分别从两个节点开始,沿着parent指针走向根节点,得到两个链表,然后求两个链表的第一个公共节点,这个方法很简单,不需要详细解释的。情况二:节点只有左、右指针,没有par...

2013-09-30 17:12:56 533

原创 [leetcode]Gas Station

Gas Station AC Rate: 296/1493 There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it co...

2013-09-30 16:40:49 77

原创 [leetcode] Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if ...

2013-09-30 12:00:55 175

原创 [leetcode] edit Distance

算法思想 动态规划。假设字符下标从1开始。c[i][j] 表示word1[1~i] 到word2[1~j]的最短编辑距离。则有递推式:c[i][j] = min(c[i-1][j],c[i][j-1],c[i-1][j-1])+1; if(i >= 1 && j >= 1 && word[i] != word[j])        ...

2013-09-17 22:28:03 59

原创 [leetcode]k路排序

K路排序每次相当于从K个数中选择最小的一个,加入结果数组,然后把对应的index+1,加入新的数去比较。对于简单的2路或者3路排序,从这2个或者3个中选择最小的一个是比较方便的,但是如果要从K个数中选择最小,而且这K个数会不断更新,那想一想,这里面最完美的数据结构就是小顶堆呀!堆顶永远是最小的元素,将其取出,其所在数组的index++,将之后所在数组的后一元素加入队列,再次进行比较!j...

2013-09-16 16:19:20 150

原创 [leetcode]Unique Binary Search Trees

Unique Binary Search TreesGiven 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 unique BST's. 1 3 ...

2013-09-16 11:41:15 64

原创 [leetcode]Combination sum

典型的DFS吧 这一类还有permutation啊,求组合啊,之类的~~~代码:public class Solution { private ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); public Array...

2013-09-15 15:42:56 55

原创 [leetcode]PatitionList

还是和removeDuplicateinSortedArr类似的思路 循环不变式 package oj.leetcode;import data.ListNode;/* * 从loop invariant的角度去考虑这个问题。也就能在考虑问题的时候,完成了对算法在数学意义上的证明。假设,你已经有了一个lessList,一个geList。然后,就是不断扫描...

2013-09-15 11:20:53 65

原创 [leetcode]removeNthFromend

  public ListNode removeNthFromEnd(ListNode head, int n) { // Start typing your Java solution below // DO NOT write main() function ListNode fast = head; ListNode slo...

2013-09-15 11:17:41 191

原创 [leetcode]nextPermutation

思路如下:假设当前给定permutation序列为 a1 a2 a3...an.从序列尾部a[n]开始向头部扫描,找到第一个相邻升序序列 a[i-1]< a[i] ; 因为是扫描到的第一个相邻升序,则此时有a[i]>=a[i+1]>=a[i+2]...>=a[n].从a[n]逆序遍历至a[i] 找到第一个大于a[i-1]的值a[j] ,交换a[i-1]和a...

2013-09-15 10:59:11 77

原创 [leetcode]RemoveDuplicatedInsortedArray

Search in Rotated Sorted Array Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another arra...

2013-09-10 17:01:39 81

原创 [leetcode]Best Time to Buy and Sell Stock

Best Time to Buy and Sell StockSay you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy on...

2013-09-09 11:50:35 81

原创 归并排序链表

/* * Merge two sorted linked lists and return it as a new list. * The new list should be made by splicing together the nodes of the first two lists. */public class MergeTwoSortedList { cl...

2013-08-29 10:54:48 95

原创 [原创]HttpClient连接池原理及一次连接时序图

转载请注明出处!谢谢1.       httpClient介绍HttpClient是一个实现了http协议的开源Java客户端工具库,可以通过程序发送http请求。 1.1.  HttpClient发送请求和接收响应1.1.1.      代码示例以Get请求为例,以下代码获得google主页内容并将返回结果打印出来。public final sta...

2013-04-09 10:33:07 587

原创 浅谈回调

本文也是在查阅了各种资料下总结的,有什么问题还望各位大牛指正~ 一. 基本概念  回调是一种双向调用的模式。被调用方在接口被调用时也会调用对方的接口。恩,具体来说,就是调用者A调用了被调用者B的方法,然后在B的这个方法体内又调用了A的方法。概念听起来很抽象。举个例子说明下,比如今天你去饭店吃饭,可是人满需要排队,于是你在饭店登记了一下(告诉他们你的手机号),告知他们如果有地方了就电话联系你。这...

2013-03-04 22:57:21 111

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

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