07 2014 档案

摘要:单例模式单例对象(Singleton)是一种常用的设计模式。在Java应用中,单例对象能保证在一个JVM中,该对象只有一个实例存在。这样的模式有几个好处:1、某些类创建比较频繁,对于一些大型的对象,这是一笔很大的系统开销。2、省去了new操作符,降低了系统内存的使用频率,减轻GC压力。3、有些类如交... 阅读全文
posted @ 2014-07-30 11:09 jdflyfly 阅读(339) 评论(0) 推荐(0)
摘要:转自知乎:http://www.zhihu.com/question/197324731.同步与异步同步和异步关注的是消息通信机制 (synchronous communication/ asynchronous communication) 所谓同步,就是在发出一个*调用*时,在没有得到结果之前... 阅读全文
posted @ 2014-07-29 10:23 jdflyfly 阅读(266) 评论(0) 推荐(0)
摘要:AOP:在一个服务的流程中插入与业务逻辑无关的系统服务逻辑(例如Logging、Security),这样的逻辑称为Cross-cutting concerns,将Cross-cutting concerns独立出来设计为一个对象,这样的特殊对象称之为Aspect,Aspect-oriented pr... 阅读全文
posted @ 2014-07-25 11:10 jdflyfly 阅读(446) 评论(0) 推荐(0)
摘要:软件模块之间总是存在着一定的接口,从调用方式上,可以把他们分为三类:同步调用、回调和异步调用。同步调用是一种阻塞式调用,调用方要等待对方执行完毕才返回,它是一种单向调用;回调是一种双向调用模式,也就是说,被调用方在接口被调用时也会调用对方的接口;异步调用是一种类似消息或事件的机制,不过它的调用方向刚... 阅读全文
posted @ 2014-07-15 10:47 jdflyfly 阅读(234) 评论(0) 推荐(0)
摘要:根据冲突解决的不同,可分为seperate chaining hash table, linear probing hash table, quadratic probing hash table.自己实现的最简单饿seperate chaining hash table。package ADT;i... 阅读全文
posted @ 2014-07-14 00:37 jdflyfly 阅读(757) 评论(0) 推荐(0)
摘要:设计一个类,我们只能生成该类的一个实例。单线程可用,多线程不安全:public class Singleton { private static Singleton instance = null; private Singleton() { } public static ... 阅读全文
posted @ 2014-07-10 00:19 jdflyfly 阅读(133) 评论(0) 推荐(0)
摘要:参考:http://blog.csdn.net/fightforyourdream/article/details/16843303import java.util.ArrayList;import java.util.Iterator;import java.util.LinkedList;imp... 阅读全文
posted @ 2014-07-09 00:16 jdflyfly 阅读(379) 评论(0) 推荐(0)
摘要:转+修改整理。import java.util.ArrayList;import java.util.Comparator;import java.util.HashMap;import java.util.PriorityQueue;import java.util.Stack;/** * htt... 阅读全文
posted @ 2014-07-08 22:42 jdflyfly 阅读(225) 评论(0) 推荐(0)
摘要:检测链表是否是palindrome.思路1:翻转并比较。思路2:迭代。思路3:递归。 public static boolean isPalindrome(LinkedListNode head) { LinkedListNode fast = head; Link... 阅读全文
posted @ 2014-07-08 00:23 jdflyfly 阅读(177) 评论(0) 推荐(0)
摘要:Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.DEFINITIONCircular linked list: A (corrupt) linke... 阅读全文
posted @ 2014-07-08 00:18 jdflyfly 阅读(118) 评论(0) 推荐(0)
摘要:You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s ... 阅读全文
posted @ 2014-07-08 00:12 jdflyfly 阅读(129) 评论(0) 推荐(0)
摘要:参考http://www.cnblogs.com/jdflyfly/p/3819162.html 阅读全文
posted @ 2014-07-08 00:11 jdflyfly 阅读(133) 评论(0) 推荐(0)
摘要:Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node. 阅读全文
posted @ 2014-07-07 23:41 jdflyfly 阅读(112) 评论(0) 推荐(0)
摘要:Implement an algorithm to find the kth to last element of a singly linked list. 阅读全文
posted @ 2014-07-07 23:34 jdflyfly 阅读(129) 评论(0) 推荐(0)
摘要:Write code to remove duplicates from an unsorted linked list. 阅读全文
posted @ 2014-07-07 23:28 jdflyfly 阅读(145) 评论(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”). 阅读全文
posted @ 2014-07-07 23:07 jdflyfly 阅读(186) 评论(0) 推荐(0)
摘要:Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0. 阅读全文
posted @ 2014-07-07 23:03 jdflyfly 阅读(103) 评论(0) 推荐(0)
摘要:Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place? 阅读全文
posted @ 2014-07-07 23:00 jdflyfly 阅读(178) 评论(0) 推荐(0)
摘要:Given an input string, reverse the string word by word. 阅读全文
posted @ 2014-07-07 22:25 jdflyfly 阅读(189) 评论(0) 推荐(0)
摘要:Evaluate the value of an arithmetic expression in Reverse Polish Notation. 阅读全文
posted @ 2014-07-07 22:22 jdflyfly 阅读(563) 评论(0) 推荐(0)
摘要:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 阅读全文
posted @ 2014-07-07 21:34 jdflyfly 阅读(184) 评论(0) 推荐(0)
摘要:Sort a linked list using insertion sort. 阅读全文
posted @ 2014-07-07 21:20 jdflyfly 阅读(158) 评论(0) 推荐(0)
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. 阅读全文
posted @ 2014-07-07 21:16 jdflyfly 阅读(250) 评论(0) 推荐(0)
摘要:Given a binary tree, return the postorder traversal of its nodes' values. 阅读全文
posted @ 2014-07-07 14:26 jdflyfly 阅读(197) 评论(0) 推荐(0)
摘要:Given a binary tree, return the preorder traversal of its nodes' values. 阅读全文
posted @ 2014-07-07 14:21 jdflyfly 阅读(167) 评论(0) 推荐(0)
摘要:Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… 阅读全文
posted @ 2014-07-07 13:35 jdflyfly 阅读(188) 评论(1) 推荐(0)
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. 阅读全文
posted @ 2014-07-07 13:13 jdflyfly 阅读(1242) 评论(3) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it. 阅读全文
posted @ 2014-07-07 13:07 jdflyfly 阅读(203) 评论(0) 推荐(0)
摘要:Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. 阅读全文
posted @ 2014-07-07 12:38 jdflyfly 阅读(149) 评论(0) 推荐(0)
摘要:Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. 阅读全文
posted @ 2014-07-07 01:12 jdflyfly 阅读(221) 评论(0) 推荐(0)
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 阅读全文
posted @ 2014-07-07 01:06 jdflyfly 阅读(200) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appears three times except for one. Find that single one. 阅读全文
posted @ 2014-07-07 01:03 jdflyfly 阅读(304) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appears twice except for one. Find that single one. 阅读全文
posted @ 2014-07-07 00:32 jdflyfly 阅读(153) 评论(0) 推荐(0)
摘要:There are N children standing in a line. Each child is assigned a rating value. 阅读全文
posted @ 2014-07-07 00:23 jdflyfly 阅读(147) 评论(0) 推荐(0)
摘要:There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. 阅读全文
posted @ 2014-07-07 00:12 jdflyfly 阅读(167) 评论(0) 推荐(0)
摘要:Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. 阅读全文
posted @ 2014-07-06 23:18 jdflyfly 阅读(162) 评论(0) 推荐(0)
摘要:Given a string s, partition s such that every substring of the partition is a palindrome. 阅读全文
posted @ 2014-07-06 23:10 jdflyfly 阅读(183) 评论(0) 推荐(0)
摘要:Given a string s, partition s such that every substring of the partition is a palindrome. 阅读全文
posted @ 2014-07-06 22:59 jdflyfly 阅读(275) 评论(0) 推荐(0)
摘要:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. 阅读全文
posted @ 2014-07-06 22:54 jdflyfly 阅读(228) 评论(0) 推荐(0)
摘要:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. 阅读全文
posted @ 2014-07-06 22:47 jdflyfly 阅读(142) 评论(0) 推荐(0)
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. 阅读全文
posted @ 2014-07-06 22:43 jdflyfly 阅读(154) 评论(0) 推荐(0)
摘要:Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end 阅读全文
posted @ 2014-07-05 00:26 jdflyfly 阅读(236) 评论(0) 推荐(0)
摘要:Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: 阅读全文
posted @ 2014-07-03 22:50 jdflyfly 阅读(186) 评论(0) 推荐(0)
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 阅读全文
posted @ 2014-07-03 22:19 jdflyfly 阅读(168) 评论(0) 推荐(0)
摘要:ay 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 at most two transactions. 阅读全文
posted @ 2014-07-03 22:15 jdflyfly 阅读(151) 评论(0) 推荐(0)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. 阅读全文
posted @ 2014-07-03 21:59 jdflyfly 阅读(149) 评论(0) 推荐(0)
摘要:ay you have an array for which the ith element is the price of a given stock on day i. 阅读全文
posted @ 2014-07-03 21:53 jdflyfly 阅读(215) 评论(0) 推荐(0)
摘要:Given a binary tree, find the maximum path sum. 阅读全文
posted @ 2014-07-03 21:42 jdflyfly 阅读(163) 评论(0) 推荐(0)
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. 阅读全文
posted @ 2014-07-03 21:30 jdflyfly 阅读(156) 评论(0) 推荐(0)
摘要: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? 阅读全文
posted @ 2014-07-03 21:17 jdflyfly 阅读(235) 评论(3) 推荐(0)
摘要:Given an index k, return the kth row of the Pascal's triangle. 阅读全文
posted @ 2014-07-03 21:06 jdflyfly 阅读(176) 评论(0) 推荐(0)
摘要:Given numRows, generate the first numRows of Pascal's triangle. 阅读全文
posted @ 2014-07-03 21:01 jdflyfly 阅读(141) 评论(0) 推荐(0)
摘要:Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. 阅读全文
posted @ 2014-07-03 20:55 jdflyfly 阅读(166) 评论(0) 推荐(0)
摘要:Implement an method to compress the string according to the number of occurrences of each char in the string. For example, "aabcccaa" is compressed as "a2b1c3a2". If the string after the compression is not shorter, return the original string. 阅读全文
posted @ 2014-07-03 09:56 jdflyfly 阅读(163) 评论(0) 推荐(0)
摘要:Write a method to replace all spaces in a string with ‘%20’. 阅读全文
posted @ 2014-07-03 09:37 jdflyfly 阅读(147) 评论(0) 推荐(0)
摘要:Write a method to decide if two strings are anagrams or not. 阅读全文
posted @ 2014-07-03 09:34 jdflyfly 阅读(162) 评论(0) 推荐(0)
摘要:Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.) 阅读全文
posted @ 2014-07-03 09:31 jdflyfly 阅读(134) 评论(0) 推荐(0)
摘要:Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? 阅读全文
posted @ 2014-07-03 09:29 jdflyfly 阅读(256) 评论(0) 推荐(0)
摘要:Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the orig... 阅读全文
posted @ 2014-07-03 00:32 jdflyfly 阅读(164) 评论(0) 推荐(0)
摘要:Given a binary tree, flatten it to a linked list in-place. 阅读全文
posted @ 2014-07-03 00:09 jdflyfly 阅读(190) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. 阅读全文
posted @ 2014-07-03 00:03 jdflyfly 阅读(244) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. 阅读全文
posted @ 2014-07-03 00:00 jdflyfly 阅读(211) 评论(0) 推荐(0)
摘要:Given a binary tree, find its minimum depth. 阅读全文
posted @ 2014-07-02 23:58 jdflyfly 阅读(237) 评论(0) 推荐(0)
摘要:Given a binary tree, determine if it is height-balanced. 阅读全文
posted @ 2014-07-02 23:55 jdflyfly 阅读(272) 评论(0) 推荐(0)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 阅读全文
posted @ 2014-07-02 23:48 jdflyfly 阅读(169) 评论(0) 推荐(0)
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 阅读全文
posted @ 2014-07-02 23:40 jdflyfly 阅读(132) 评论(0) 推荐(0)
摘要:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). 阅读全文
posted @ 2014-07-02 23:37 jdflyfly 阅读(143) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. 阅读全文
posted @ 2014-07-02 23:33 jdflyfly 阅读(129) 评论(0) 推荐(0)
摘要:Given inorder and postorder traversal of a tree, construct the binary tree. 阅读全文
posted @ 2014-07-02 23:05 jdflyfly 阅读(201) 评论(0) 推荐(0)
摘要:Given a binary tree, find its maximum depth. 阅读全文
posted @ 2014-07-02 23:02 jdflyfly 阅读(118) 评论(0) 推荐(0)
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). 阅读全文
posted @ 2014-07-02 23:00 jdflyfly 阅读(152) 评论(0) 推荐(0)
摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). 阅读全文
posted @ 2014-07-02 22:54 jdflyfly 阅读(148) 评论(0) 推荐(0)
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). 阅读全文
posted @ 2014-07-02 22:46 jdflyfly 阅读(184) 评论(0) 推荐(0)
摘要:Given two binary trees, write a function to check if they are equal or not. 阅读全文
posted @ 2014-07-02 22:43 jdflyfly 阅读(141) 评论(0) 推荐(0)
摘要:Two elements of a binary search tree (BST) are swapped by mistake. 阅读全文
posted @ 2014-07-02 22:36 jdflyfly 阅读(135) 评论(0) 推荐(0)
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). 阅读全文
posted @ 2014-07-02 22:26 jdflyfly 阅读(148) 评论(0) 推荐(0)
摘要:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. 阅读全文
posted @ 2014-07-02 22:21 jdflyfly 阅读(181) 评论(1) 推荐(0)
摘要:Given a binary tree, return the inorder traversal of its nodes' values. 阅读全文
posted @ 2014-07-02 00:28 jdflyfly 阅读(138) 评论(0) 推荐(0)
摘要:Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. 阅读全文
posted @ 2014-07-02 00:11 jdflyfly 阅读(268) 评论(1) 推荐(0)
摘要:Given n, how many structurally unique BST's (binary search trees) that store values 1...n? 阅读全文
posted @ 2014-07-02 00:05 jdflyfly 阅读(136) 评论(0) 推荐(0)
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. 阅读全文
posted @ 2014-07-01 23:59 jdflyfly 阅读(225) 评论(0) 推荐(0)
摘要:Reverse a linked list from position m to n. Do it in-place and in one-pass. 阅读全文
posted @ 2014-07-01 23:56 jdflyfly 阅读(190) 评论(1) 推荐(0)
摘要:Given a collection of integers that might contain duplicates, S, return all possible subsets. 阅读全文
posted @ 2014-07-01 23:51 jdflyfly 阅读(231) 评论(0) 推荐(0)
摘要:Given an encoded message containing digits, determine the total number of ways to decode it. 阅读全文
posted @ 2014-07-01 23:44 jdflyfly 阅读(177) 评论(0) 推荐(0)
摘要:The gray code is a binary numeral system where two successive values differ in only one bit. 阅读全文
posted @ 2014-07-01 23:15 jdflyfly 阅读(218) 评论(0) 推荐(0)
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array. 阅读全文
posted @ 2014-07-01 22:23 jdflyfly 阅读(129) 评论(0) 推荐(0)
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. 阅读全文
posted @ 2014-07-01 22:20 jdflyfly 阅读(225) 评论(0) 推荐(0)
摘要:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. 阅读全文
posted @ 2014-07-01 22:15 jdflyfly 阅读(232) 评论(0) 推荐(0)