Java基础
文章平均质量分 71
wongson
这个作者很懒,什么都没留下…
展开
-
层次遍历二叉树
public class Solution { static class Queue { static final int MAX_SIZE = 1 << 10; private TreeNode list[]; int head; int tail; int cap; Queue() {原创 2015-04-10 17:29:18 · 656 阅读 · 0 评论 -
Best Time to Buy and Sell Stock IV
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 at most k transactions.Note:You may原创 2015-05-03 14:43:02 · 1368 阅读 · 0 评论 -
ConcurrentHashMap深入分析
ConcurrentHashMap深入分析一、Map体系Hashtable是JDK 5之前Map唯一线程安全的内置实现(Collections.synchronizedMap不算)。Hashtable继承的是Dictionary(Hashtable是其唯一公开的子类),并不继承AbstractMap或者HashMap。尽管Hashtable和HashMap的结构非常转载 2015-04-28 10:08:07 · 639 阅读 · 0 评论 -
N皇后问题
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-queens puzzle.原创 2015-05-10 12:57:12 · 599 阅读 · 0 评论 -
尾递归
尾递归递归与尾递归关于递归操作,相信大家都已经不陌生。简单地说,一个函数直接或间接地调用自身,是为直接或间接递归。例如,我们可以使用递归来计算一个单向链表的长度:public class Node{ public Node(int value, Node next) { this.Value = value; this.Ne转载 2015-05-08 21:07:57 · 503 阅读 · 0 评论 -
文件路径化简
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case where path原创 2015-04-29 16:37:14 · 841 阅读 · 0 评论 -
生成所有的BST
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3原创 2015-04-29 13:23:54 · 1145 阅读 · 0 评论 -
平衡二叉树判定
1. int height(TreeNode root) { if (root == null) return 0; return Math.max(height(root.left), height(root.right)) + 1; } public boolean isBalanced(TreeNode root) { if原创 2015-04-29 18:44:48 · 631 阅读 · 0 评论 -
求二叉树最远距离
int max=Integer.MIN_VALUE; int maxHeightSum(TreeNode root) { if (root == null) return 0; int maxL = Math.max(maxHeightSum(root.left), 0); int maxR = Math.max(maxHeightSum原创 2015-04-25 19:14:19 · 666 阅读 · 0 评论 -
java动态代理(JDK和cglib)
JAVA的动态代理 代理模式 代理模式是常用的java设计模式,他的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息、过滤消息、把消息转发给委托类,以及事后处理消息等。代理类与委托类之间通常会存在关联关系,一个代理类的对象与一个委托类的对象关联,代理类的对象本身并不真正实现服务,而是通过调用委托类的对象的相关方法,来提供特定的服务。 按照代理的创建时期,代理类可以分为转载 2015-04-26 22:27:08 · 454 阅读 · 0 评论 -
LRU cache
实现lru 缓存LRU Cache Total Accepted: 35641 Total Submissions: 241374My SubmissionsQuestion Solution Design and implement a data structure for Least Recently Used (LRU) c原创 2015-04-09 15:28:19 · 903 阅读 · 0 评论 -
变位分词
static int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101}; static public int mapping(String s) { int val = 1; for原创 2015-04-24 22:44:32 · 737 阅读 · 0 评论 -
复制无向带环图
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each原创 2015-04-13 16:06:04 · 1064 阅读 · 0 评论 -
先序和中序建立二叉树
Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in th原创 2015-04-23 12:50:36 · 1682 阅读 · 0 评论 -
合法ip序列
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2015-04-23 17:35:14 · 766 阅读 · 0 评论 -
Java agent实现JVM exception 统计
Java agent实现JVM异常监控原理对于javaagent,或许大家都听过,甚至使用过,常见的用法大致如下:java -javaagent:myagent.jar=mode=test Test我们通过-javaagent来指定我们编写的agent的jar路径(./myagent.jar),以及要传给agent的参数(mode=test),在启动的时候这个agent就可以做一些我们希望的事了。j原创 2016-07-05 10:24:43 · 1631 阅读 · 0 评论