`
dugu108
  • 浏览: 23318 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表

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 palindrome. Note:Have you consider that the string might be empty? This is a good que ...
JSON本身就是个简单的不能再简单的玩意,既然要和java做转换,必然有些开源的玩意,貌似Codehaus的Jackson还是比较不错,转载一篇全面介绍以作纪念。   Jackson 框架,轻易转换JSON Jackson可以轻松的将Java对象转换成json对象和xml ...
 给定一个有序整数序列(非递减序),可能包含负数,找出其中绝对值最小的元素,比如给定序列-5, -3, -1, 2, 8 则返回1。 public class MinAbs { public static int calculate(int[] array) { return calculate(array, 0, array.length - 1); } public static int calculate(int[] array, int low, int high) { if (low == high) { ...
给定含有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 void doMove(int[] array) { for (int i = array.length - 2; i >= 0; i--) { if (ar ...
参考官方文档安装PostgreSQL9.1  apt-get install postgresql-9.1 这包括以下主要packages postgresql-client-9.1 - client libraries and client binaries postgresql-9.1 - core database server postgresql-contrib-9.1 - additional supplied modules libpq-dev - libraries and headers for C language frontend developmen ...
       今天在尝试使用jetty7+cometd+spring的archetype建立工程时,无法按照reference预期的出现正常的访问结果,出现了org.apache.jasper.JasperException: java.err.nojdk。 org.apache.jasper.JasperException: java.err.nojdk at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:89) at org.apache.jasper.compi ...
最大连续子数组的积 不考虑溢出,注意多个0,多个负数,还有结果是1的情况 public class MaxSubMultiplication { public static int calculate(int[] array) { int lastZeroIndex = -1; int indexOfFirstNegative = -1; int indexOfLastNegative = -1; int mulBeforeFirst = 1; int mulAfterLast = 1; ...

最大公约数

最大公约数 public class Euclid { public static int gcd(int m, int n) { int tmp = 0; do { tmp = n % m; n = m; m = tmp; } while (tmp != 0); return n; } public static void main(String[] args) { System.out.p ...
最大子数组之和   给定一个整型数组a,求出最大连续子段之和,如果和为负数,则按0计算,比如1, 2, -5, 6, 8则输出14 public class MaxSubSum { public static int calculate(int[] array) { int max = 0; int tmp = 0; for (int i = 0; i <= array.length-1; i++) { if (tmp + array[i] > 0) { ...

基本快排

快排 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) { if (low >= high) { return; } int i = low + 1; ...
求两数组中满足给定和的数对    给定两个有序整型数组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.length == b.length); int i = 0; int j = b.length - 1; int repeat = 0; ...

数组全排列

数组全排列,不考虑重复值 public class AllPermutation { public static void doPermute(Character[] array) { doPermute(array, 0); } public static void doPermute(Character[] array, int start) { if (start == array.length - 1) { Utils.print(array); return; ...

递归汉诺塔

递归汉诺塔     public class HanoiQuestion { private static void move(char from, char to) { System.out.println("move the top plate from " + from + " to " + to); } public static void hanoi(char from, char to, char mid, int index) { if (index == 1) ...
合并两个数组 给定含有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[] doMerge(int[] a, int[] b) { int[] tmp = new int[a.length + b.length]; tmp[0] = 0; int i = ...
Global site tag (gtag.js) - Google Analytics