自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 SDL实现生产者消费者

环境:阿里云主机CPU: 1核     内存: 1GB    数据盘:  20G操作系统: Ubuntu 12.04 64位 1.       SDL安装[root@iZ25ml7xjj1Z:/usr/lixian]$sudo aptitude install libsdl1.2debian 2.       生产者消费者源代码

2014-11-03 20:12:23 1116

原创 3Sum

Problem:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a tr

2014-10-27 09:43:19 384

原创 Generate Parentheses

Problem:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "

2014-10-25 11:36:35 439

原创 Merge k Sorted Lists

Problem:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.采用分治来做。两两合并链表,直到只剩下1个链表。时间复杂度为O(m*n*log(n)),而顺序合并的时间复杂度为O(m*n^2)。Solution:

2014-10-24 23:25:36 416

原创 Implement strStr()

Problem:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.我实现了Boyer-Moore算法,效果非常好,12ms就跑下来了。BM算法的效率非常高,优于KMP算法。算

2014-10-23 21:11:38 398

原创 Search for a Range

Problem:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target

2014-10-15 15:54:59 384

原创 Search Insert Position

Problem:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates

2014-10-15 14:28:11 377

原创 Sudoku Solver

Problem:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.

2014-10-15 10:05:37 466

原创 Count and Say

Problem: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.11 is read off as "two 1s" or 21.21 i

2014-10-14 11:13:09 409

原创 Combination Sum II

Problem:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once 

2014-10-14 10:31:26 422

原创 Nutch+Lucene搜索引擎开发实践

使用开源工具Nutch和Lucene在局域网下搭建垂直搜索引擎。

2014-10-14 09:26:55 2872

转载 UML类图与类的关系详解

UML类图与类的关系详解在画类图的时候,理清类和类之间的关系是重点。类的关系有泛化(Generalization)、实现(Realization)、依赖(Dependency)和关联(Association)。其中关联又分为一般关联关系和聚合关系(Aggregation),合成关系(Composition)。下面我们结合实例理解这些关系。基本概念

2014-10-14 09:09:06 503

原创 Combination Sum

Problem:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C 

2014-10-13 22:32:50 503 1

原创 京东2015校招笔试编程题

这道题就是丑数问题,在《剑指Offer》一书的182页有详细讨论。简单来说,就是:新的丑数总是以前的某个丑数乘以2、3或5产生,那么分别用三个指针p2、p3和p5指向乘以2、3和5后能生成新的丑数的丑数,那么下一个丑数就是它们生成的新的丑数中最小的一个。public static int KthNumber(int k){    int[] uglyNumbers = new

2014-10-11 23:00:11 855

原创 First Missing Positive

Problem:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and

2014-10-11 09:12:26 357

原创 Trapping Rain Water

Problem:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,

2014-10-10 21:32:06 415

原创 Multiply Strings

Problem:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.   大数乘法,通常采用的是模拟手工计算的方法,时

2014-10-10 15:50:02 343

转载 JSON解析工具-org.json使用教程

一、简介 org.json是Java常用的Json解析工具,主要提供JSONObject和JSONArray类,现在就各个类的使用解释如下。 二、准备 1.在使用org.json之前,我们应该先从该网址https://github.com/douglascrockford/JSON-java下载org.json源码,并将源码其加入到Eclipse中,

2014-10-10 10:18:02 426

原创 重写equals方法

equals方法用于判断当前对象this与另一个对象obj是否相等。必须遵守的规则:• 对称性:如果x.equals(y)返回是“true”,那么y.equals(x)也应该返回是“true”。 • 反射性:x.equals(x)必须返回是“true”。 • 类推性:如果x.equals(y)返回是“true”,而且y.equals(z)返回是“true”,那么z.equa

2014-10-10 10:15:10 437

翻译 CloudSim类设计

BwProvisioner: 这个抽象类为VM的带宽配置策略建模。该模块的主要功能是向在数据中心部署的相互竞争的VM分配网络带宽。云系统开发者可以用他们自己的策略(优先级,QoS)来扩展该类。BwProvisioningSimple允许VM根据需求尽可能多的保留带宽,但是会受到托管主机的总可用带宽限制。CloudCoordinator: 这个抽象类把一个云数据中心扩展到联盟,负责周期性监测

2014-10-10 10:13:41 1418

原创 重写hashCode方法

hashCode方法在Object类中定义如下:public native int hashCode();说明是一个本地方法,其实现和本地机器相关。我们可以在自己的类中覆盖hashCode方法。下面String类中重写的hashCode方法:public int hashCode() {     int h = hash;     if (h == 0) {

2014-10-10 10:13:25 1928

翻译 CloudSim内核仿真框架

GridSim是CloudSim的构件之一。GridSim使用SimJava库作为事件处理和实体间的消息传递的框架。SimJava在搭建可扩展的仿真环境时存在局限性。比如:它不允许在运行时通过编程重置仿真环境。它不支持在运行时创建新的仿真实体。随着系统规模的扩展,SimJava的多线程属性会带来性能上的开销。性能的下降是由线程间过度的上下文切换导致的。多线程处理会使

2014-10-10 10:11:57 885

原创 使用EclEmma进行覆盖测试

EclEmma是一个开源 Java 覆盖测试工具。进入下面的链接按提示安装集成到Eclipse中。http://www.eclemma.org/installation.html安装完成后,就可以在Eclipse的tool menu中看到EclEmma的icon了。单击此按钮,选择事先写好的JUnit test程序,就可以对代码进行覆盖测试了。测试完成后

2014-10-10 10:07:32 670

原创 XML转JSON

依赖的包:org.json.jar,commons-io-2.2.jar获取xml文件的InputStream is,使用IOUtils把is转成String。调用XML的toJSONObject方法获取JSON对象。import org.apache.commons.io.IOUtils;import org.json.*;InputStream

2014-10-10 10:06:03 804

原创 Eclipse 远程调试

在远程服务器上执行命令:root@raspberrypi:/home/cheng# java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address="8000" -jar cli.jar ​在本地Eclipse中选中调试的项目,右键选择Debug as->Debug Configurations,出现Debug C

2014-10-10 09:59:25 493

原创 卸载MySQL,安装SQLite

卸载MySQL:#sudo apt-get autoremove --purge mysql-server-5.0出现是否继续选项时,选yDo you want to continue [Y/n]? y出现warning,可以卸载完成后手动删除/etc/mysql。dpkg: warning: while removing mysql-common, direc

2014-10-10 09:56:20 985

原创 Wildcard Matching

Problem:Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching

2014-10-10 09:48:12 280

原创 Jump Game II

Problem: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.

2014-10-09 20:43:31 451

原创 亚马逊2015校招在线笔试2

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Arrays;import java.util.HashMap;public class AmazonOnline2 {public static voi

2014-10-09 17:23:39 1188

原创 Permutations II

Problem:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1],

2014-10-09 13:50:03 389

原创 Permutations

Problem:Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 

2014-10-09 13:25:26 537

原创 亚马逊2015校招在线笔试1

截图有重叠,大家将就一下。本人没有参加在线笔试,主要跟大家分享一下思路。    题目的意思就是找到从起始节点开始的定长路径,路径必须包含一个必须要到达的节点。返回所有的路径数,如果不存在这样的路径,则返回0。    既然要找到所有路径,那就采用广搜。如果路径长度达到指定长度,则检查路径中是否包含必须要到达的节点,如果包含,路径数加1;如果路径长度没有达到指定长度,则从当前路径的末节

2014-10-09 12:39:23 1190

原创 Rotate Image

Problem:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?    就是求矩阵的转置,如果不计空间复杂度,新建一个矩阵,按行复制到列就行了

2014-10-08 16:35:05 318

原创 N-Queens

Problem:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.​Given an integer n, return all distinct solutions to the n-

2014-10-08 10:19:40 335

原创 Jump Game

Problem: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.

2014-10-07 21:08:37 415

原创 Merge Intervals

Problem:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].​先根据start按升序排序,再依序合并重叠区间。为了节省空间,实现

2014-10-07 20:31:52 373

原创 Insert Interval

Problem:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their sta

2014-10-07 16:42:42 399

原创 Rotate List

Problem:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.移动p,q指针到下图所示的位置。然

2014-10-07 12:19:31 372

原创 Unique Paths II

Problem:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respecti

2014-10-07 09:53:33 359

原创 Unique Paths

Problem:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying

2014-10-06 23:28:06 350

空空如也

空空如也

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

TA关注的人

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