长颈鹿Giraffe

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  Java

摘要:原文地址:http://blog.griddynamics.com/2011/06/understanding-gc-pauses-in-jvm-hotspots.htmlStop-the-world pauses of JVM due to the work of garbage collecto... 阅读全文
posted @ 2014-09-02 15:33 长颈鹿Giraffe 阅读(1003) 评论(0) 推荐(0)

摘要:web.xml中的配置: log4jConfigLocation /WEB-INF/log4j.properties log4jRefreshInterval 60000 org.springframework.web.util.Log4jConfigListenerlog4j.... 阅读全文
posted @ 2014-04-22 15:21 长颈鹿Giraffe 阅读(825) 评论(0) 推荐(0)

摘要:如何你的DispatcherServlet拦截 *.do这样的URL,就不存在访问不到静态资源的问题。如果你的DispatcherServlet拦截“/”,拦截了所有的请求,同时对*.js,*.jpg的访问也就被拦截了。目的:可以正常访问静态文件,不要找不到静态文件报404。方案一:激活Tomcat的defaultServlet来处理静态文件Xml代码 default *.jpg default *.js default *.css 要配置多个,... 阅读全文
posted @ 2014-03-24 00:28 长颈鹿Giraffe 阅读(371) 评论(0) 推荐(0)

摘要:收集的一些kafka的信息:http://my.oschina.net/geecoodeer/blog/194829 阅读全文
posted @ 2014-03-24 00:19 长颈鹿Giraffe 阅读(270) 评论(0) 推荐(0)

摘要:Write code to partition a linked list around a value x, such that all nodes less than xcome before alt nodes greater than or equal to.分割一个链表,将值小于x的节点全部放在其他节点的前面。解答:我们可以创建两个不同的链表,其中一个用来连接比x小的节点,另外一个则连接大于等于x的节点,然后合并两个链表即可。public class Main { public static void appendToTail(List head, int d) { ... 阅读全文
posted @ 2013-07-24 12:12 长颈鹿Giraffe 阅读(497) 评论(0) 推荐(0)

摘要:Implement an algorithm to delete a node in the middle of a singly linked list,given only access to that node.EXAMPLEInput: the node c from the linked list a->b->c->d->eResult: nothing is returned, but the new linked list looks like a- >b- >d->e删除链表中的一个节点,但并没有给出链表的头结点,而是只能访问要删除的这 阅读全文
posted @ 2013-07-24 11:34 长颈鹿Giraffe 阅读(334) 评论(0) 推荐(0)

摘要:Implement an algorithm to find the kth to last element of a singly linked list.实现一个算法寻找链表中倒数第K个数..解答:关于链表的问题,书中也提到了关键的两个技巧,一个是递归;另一个是The"Runner"Technique,也就是使用两个指针同时遍历链表的方式。这道题可以分别用这两种方法来解决。import java.util.HashMap;public class List { int data; List next; public List(int d) { this.da... 阅读全文
posted @ 2013-07-24 11:07 长颈鹿Giraffe 阅读(315) 评论(0) 推荐(0)

摘要:原文:Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?译文:删除链表中的重复元素,另外,如果不使用临时存储空间怎么做?解答:如果空间没有限制,那么用一个map来标记链表中出现过的元素,然后从头到尾扫一遍链表,把出现过的删除就行了。时间复杂度O(n)。如果限制空间,那么可以设置两个指针n、m,当n指向某个元素时,m把该元素后面与它相同的元素删除, 时间复杂度O(n2) 阅读全文
posted @ 2013-07-23 11:52 长颈鹿Giraffe 阅读(311) 评论(0) 推荐(0)

摘要:原文:Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring ( i.e., “waterbottle” is a rotation of “erbottlewat”).译文:假设你有一个isSubstring函数,可以检测一个字符串是否是另一个字符串的子 阅读全文
posted @ 2013-07-12 17:49 长颈鹿Giraffe 阅读(249) 评论(0) 推荐(0)

摘要:原文Write an algorithm such that if an element in an MxN matrix is 0, its entire row andcolumn are set to 0.译文写一个算法,如果一个MxN中的一个元素为0,那么将这个元素所在的行和列都设置为0。解答遍历一次矩阵,当遇到元素等于0时,记录下这个元素对应的行和列。并设置一个标记。在遍历完之后,再根据之前的标记设置矩阵的值。import java.util.BitSet;public class Main { public static void setZero(int[][] mat, i... 阅读全文
posted @ 2013-07-12 17:35 长颈鹿Giraffe 阅读(317) 评论(0) 推荐(0)

摘要:原文:Given an image represented by an NxN matrix, where each pixel in the image is 4bytes, write a method to rotate the image by 90 degrees. Can you do this in place?译文给一个NxN的矩阵,写一个函数把矩阵旋转90度。 并且要求在原矩阵上进行操作,即不允许开辟额外的存储空间。解答(一)Hawstein在他的Blog中http://hawstein.com/posts/1.6.html介绍的方法是:可以分两步走。 第一步交换主对角线两侧 阅读全文
posted @ 2013-07-12 17:21 长颈鹿Giraffe 阅读(330) 评论(0) 推荐(0)

摘要:原文Implement a method to perform basic string compression using the countsof repeated characters. For example, the string aabcccccaaa would becomea2blc5a3. If the "compressed" string would not become smaller than the originalstring, your method should return the original string.译文利用计算字符个数的方 阅读全文
posted @ 2013-07-12 15:02 长颈鹿Giraffe 阅读(346) 评论(0) 推荐(0)

摘要:原文Write a method to replace all spaces in a string with'%20'. You may assume thatthe string has sufficient space at the end of the string to hold the additionalcharacters, and that you are given the "true" length of the string. (Note: if implementingin Java, please use a character 阅读全文
posted @ 2013-07-12 13:35 长颈鹿Giraffe 阅读(292) 评论(0) 推荐(0)

摘要:原文Given two strings, write a method to decide if one is a permutation of the other.译文给你两个字符串,写一个方法来判断其中一个是不是另一个的permutation。如果两个字符串含有相同的字符,仅仅是顺序可能不同,那么他们就叫permutations。例如"ABCDEF"和"FEDCBA",我们可以认为它们是permutation。解答如果长度不同,则一定不是,否则我们可以先将两个字符串内的字符按字典序排序,然后再判断是否相等。import java.util.Array 阅读全文
posted @ 2013-07-12 11:55 长颈鹿Giraffe 阅读(455) 评论(0) 推荐(0)

摘要:原文Implement a function void reverse(char* str) in C or C++ which reverses a null-terminatedstring.译文用C或者C++实现一个void reverse(char* str)的函数来逆转一个已null终止的字符串解答在C++里,设置俩指针,一个指向字符串头,一个指向尾,然后每次交换一个字符和,指针分别像中间移就行了。这里借用一下Hawstein(http://hawstein.com/posts/1.2.html)的代码好了:#include #include using namespace std; 阅读全文
posted @ 2013-07-12 11:33 长颈鹿Giraffe 阅读(364) 评论(0) 推荐(0)

摘要:原文:Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?译文:实现一个算法来判断一个字符串中的字符是否唯一(即没有重复).不能使用额外的数据结构。 (即只使用基本的数据结构)解答:假设题目中提到的字符是包含在ASCII中的字符的话,那么最多是256个。所以可以用一个256长的数组来标记,或者用一个8个32位的int值来标记。如果题目中没有规定只使用基本的数据结构的话,用BitSet来做也很方便的 阅读全文
posted @ 2013-07-12 11:09 长颈鹿Giraffe 阅读(310) 评论(0) 推荐(0)

摘要:1. Arrays and Strings1.1Hash Tables哈希表,简单的说就是由一个数组和一个hash函数组成实现key/value映射并且能高效的查找的数据结构。最简单的想法就是将hash(key)做为数组的下标(index)来存取。但是为了防止hash的冲突(collisions),数组的大小必须设置得足够大,因此上面这种简单的实现在实际中是不可取的。实际上,哈希表是一个固定大小的数组,数组的每个元素是一个链表(单向或双向)的头指针。每个元素被存放在hash(key)%array_length所在的链表中。如下图所示:另外,我们可以用二叉查找树(bst)来实现哈希表,在平衡树的 阅读全文
posted @ 2013-07-10 12:18 长颈鹿Giraffe 阅读(628) 评论(0) 推荐(0)

摘要:参考了一些论文和网上的资料以及清华大学出版社出版的《自己动手写网络爬虫》这本书中的部分章节,设计了主题爬虫的主要体系结构如下图所示: Heritrix是一个由 java 开发的、开源的网络爬虫,我参考网上的一些文章分析了其部分关键功能的代码,然后借鉴其几个比较好的地方实现了一个通用爬虫的主要功能。下面是我实现的爬虫中几个个人认为比较好的地方。1) 可配置性:通过.properties配置文件可以配置该爬虫所使用的线程数、线程等待时间,连接超时时间,可爬取文件类型和下载目录等。2) 爬虫礼仪:解析站点根目录下的robots.txt文件,遵循爬虫禁止协议、以及避免对服务器资源的过度使用等。3) 爬 阅读全文
posted @ 2011-12-09 15:54 长颈鹿Giraffe 阅读(1807) 评论(0) 推荐(0)

摘要:乱码对于使用非英语程序员基本上是一直缠绕在身边的麻烦事,这个谁也避免不了。以下是我的一些解决乱码问题的方法或经验的汇总,欢迎指正或补充。一、乱码发生的情况和应对措施1.开发环境乱码 由于Java默认使用UTF-8编码,而且网上很多人都建议Web开发的时候应尽量选用UTF-8做为默认编码,而非GBK。有时候或许会碰到这样的问题,成员A在他机器上看到的是正常的中文注释,你通过SVN下载到你机器上时,却发现注释全变成乱码了,这时候一定是你们的IDE的默认编码不同了。所以项目组成员在使用Eclipse等IDE的时候,应统一将default text editor改为UTF-8编码,免得日后后悔再改就. 阅读全文
posted @ 2011-10-21 22:21 长颈鹿Giraffe 阅读(435) 评论(0) 推荐(0)