自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 js闭包是什么?

尽管本身不太会js,不过通过这个文章理解了闭包 js闭包是什么?js闭包是什么?我初次接触“闭包”时,看了很多资料,总是无法理解,因为一些文章写得太“学术化”,虽然措辞非常严谨,但是对初学这来说,太难理解了。 自从看到这篇文章,我的眼前“豁然开朗”   一、什么是闭包?   “官方”的解释是:所谓“闭包”,指的是一个拥有许多变量和...

2013-05-07 16:07:15 139

堆Heap

public class Heap { public static void siftUp(int[] array, int i) { if (array == null || array.length <= 1 || i < 0 || i > array.length) { return; } while (true) { if (arr...

2013-02-23 16:39:42 106

原创 栈内元素排序

分别是利用一个辅助栈和两个辅助栈public class StackSort { public static void sortWithOneCache(Stack<Integer> stack) { if (stack == null || stack.isEmpty()) { return; } Stack<Integer> cac...

2013-02-16 20:55:25 169

二叉查找树任意两个节点的最近共同父节点

找出二叉查找树Binary search tree上任意两个节点的最近共同父节点  public class Solution { public static int findFather(BinarySearchTreeNode root, BinarySearchTreeNode n1, BinarySearchTreeNode n2) { if (n1....

2013-01-29 16:19:37 369

Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 ...

2013-01-29 15:34:56 76

原创 Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none...

2013-01-29 15:03:21 85

Populating Next Right Pointers in Each Node II

 Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant e...

2013-01-29 13:52:14 97

Populating Next Right Pointers in Each Node

 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right ...

2013-01-29 11:33:08 80

原创 Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?import java.util.Arr...

2013-01-28 23:16:02 70

Pascal's Triangle

 Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]public class Solution...

2013-01-28 17:19:48 52

找出数组中第k小的元素

给定一无序整型数组a,在不排序的情况下,查找第k小的元素类似快排。如果k非常小比如小于3,觉得应该用几个临时变量然后遍历一遍解决。 public class MinKth { public static int calculate(int[] array, int k) { return calculate(array, k, 0, array.len...

2013-01-28 16:52:03 414

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 following triangle[ [2], [3,4], [...

2013-01-28 15:31:29 84

原创 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 complete as many transactions as you like (ie, buy on...

2013-01-26 14:40:21 58

原创 Best Time to Buy and Sell Stock

Say 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 one and sell one share of the stock), ...

2013-01-26 14:31:47 79

Binary Tree Maximum Path Sum

 Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3 Return 6. ...

2013-01-26 11:33:14 68

Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palin...

2013-01-25 23:34:20 64

原创 转载:Jackson 框架,轻易转换JSON

JSON本身就是个简单的不能再简单的玩意,既然要和java做转换,必然有些开源的玩意,貌似Codehaus的Jackson还是比较不错,转载一篇全面介绍以作纪念。 Jackson 框架,轻易转换JSONJackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json、xml转换成Java对象。前面有介绍过json-lib这个框架,在线博文:http://ww...

2013-01-25 15:03:11 79

求非递减数组中最小的绝对值

 给定一个有序整数序列(非递减序),可能包含负数,找出其中绝对值最小的元素,比如给定序列-5, -3, -1, 2, 8 则返回1。public class MinAbs { public static int calculate(int[] array) { return calculate(array, 0, array.length - 1); ...

2013-01-25 13:52:57 137

数组中0的移动

给定含有n个元素的整型数组a,其中包括0元素和非0元素,对数组进行排序,要求: 1. 排序后所有0元素在前,所有非零元素在后,且非零元素排序前后相对位置不变 2. 不能使用额外存储空间 例子如下 输入 0, 3, 0, 2, 1, 0, 0 输出 0, 0, 0, 0, 3, 2, 1弱逼解法:public class MoveZero { public static voi...

2013-01-25 11:31:21 142

原创 ubuntu 安装 PostgreSQL

参考官方文档安装PostgreSQL9.1 apt-get install postgresql-9.1这包括以下主要packagespostgresql-client-9.1 - client libraries and client binariespostgresql-9.1 - core database serverpostgresql-contrib-9....

2013-01-23 17:04:21 101

解决访问Jetty页面中JSP时的java.err.nojdk

       今天在尝试使用jetty7+cometd+spring的archetype建立工程时,无法按照reference预期的出现正常的访问结果,出现了org.apache.jasper.JasperException: java.err.nojdk。org.apache.jasper.JasperException: java.err.nojdk at org.apache.j...

2013-01-22 11:21:02 338

原创 最大连续子数组的积

最大连续子数组的积不考虑溢出,注意多个0,多个负数,还有结果是1的情况public class MaxSubMultiplication { public static int calculate(int[] array) { int lastZeroIndex = -1; int indexOfFirstNegative = -1; ...

2013-01-20 21:35:25 131

原创 最大公约数

最大公约数public class Euclid { public static int gcd(int m, int n) { int tmp = 0; do { tmp = n % m; n = m; m = tmp; } while (tmp !...

2013-01-18 17:00:51 93

原创 最大子数组之和

最大子数组之和 给定一个整型数组a,求出最大连续子段之和,如果和为负数,则按0计算,比如1, 2, -5, 6, 8则输出14public class MaxSubSum { public static int calculate(int[] array) { int max = 0; int tmp = 0; fo...

2013-01-18 16:59:07 114

原创 基本快排

快排public class QuickSort { public static void sort(Comparable[] array) { sort(array, 0, array.length - 1); } public static void sort(Comparable[] array, int low, int high...

2013-01-18 14:15:07 93

原创 两数组中满足给定和的数对

求两数组中满足给定和的数对  给定两个有序整型数组a和b,各有n个元素,求两个数组中满足给定和的数对, 即对a中元素i和b中元素j,满足i + j = s(s已知) public class PairSummation { public static void execute(int[] a, int[] b, int s) { assert (a....

2013-01-18 14:13:30 319

原创 数组全排列

数组全排列,不考虑重复值public class AllPermutation { public static void doPermute(Character[] array) { doPermute(array, 0); } public static void doPermute(Character[] array, int star...

2013-01-18 14:12:02 62

原创 递归汉诺塔

递归汉诺塔  public class HanoiQuestion { private static void move(char from, char to) { System.out.println("move the top plate from " + from + " to " + to); } public stati...

2013-01-17 00:09:03 78

原创 合并顺序数组

合并两个数组给定含有n个元素的有序(非降序)整型数组a和含有m个元素的有序(非降序)整型数组b。合并两个数组中的元素到整型数组c,要求去除重复元素并保持c有序(非降序)。例子如下 a = 1, 2, 4, 8 b = 1, 3, 5, 8 c = 1, 2, 3, 4, 5, 8  public class MergeArray { public static int[...

2013-01-17 00:04:14 125

空空如也

空空如也

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

TA关注的人

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