自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 线程池与定时器

1.在什么情况下使用线程池? 1.单个任务处理的时间比较短 2.将需处理的任务的数量大 2. 使用线程池的好处: 1.减少在创建和销毁线程上所花的时间以及系统资源的开销 2.如不使用线程池,有可能造成系统创建大量线程而导致消耗完系统内存以及”过度切换”。 3. 使用线程池的风险 虽然线程池是构建多线程应用程序的强大机制,但使用它

2016-10-16 20:52:42 2077

原创 各种格式之间转换

String转json String jstr=”{‘json’:’jsonvalue’,’bool’:true,’int’:1,’double’:’20.5’}”; JSONObject json=JSONObject.fromObject(jstr); boolean bool=json.getBoolean(“bool”); int i=json.getInt(“int”); dou

2016-10-16 17:34:03 348

原创 Mock常用方法

http://www.tuicool.com/articles/J7BFr2AMock 测试是单元测试的重要方法之一。Mockito是基于Java的Mock测试框架。 什么是 Mock 测试 Mock 测试就是在测试过程中,对于某些不容易构造(如 HttpServletRequest 必须在Servlet 容器中才能构造出来)或者不容易获取比较复杂的对象(如 JDBC 中的ResultS

2016-10-16 17:19:51 11158

原创 rabbitmq组件断链重连机制

方案一: Rabbitmq在启动时,为rabbitmq设置一个status,在第一次建立连接的时候将其变为true,rabbitmq client在初始化时启动一个定时器,每隔一段时间开启一个线程,查询当前status的状态,如果status变为false,重新建立连接(包括connection、channel的连接)。方案二: Implement shutdown listener,如果rab

2016-10-16 15:43:28 16897

原创 rabbitmq的鉴权

详细内容可以查看(http://www.rabbitmq.com/access-control.html)Rabbitmq有两种鉴权方式:一种是利用内置数据库鉴权。另一种是rabbitmq-auth-backend-http鉴权插件来实现后端鉴权。 Rabbitmq中,Authentication 和 authorisation是有区别的,authentication是“identifying w

2016-10-16 15:36:57 2938

原创 rabbitmq基础

Exchange的三种typeDirect Exchange –通过binding key的完全匹配,binding key的名称与queue name的名称相同。 当P publish key是orange时,exchange会把它放到Q1。如果是black或者green那么就会到Q2。其余的Message都会被丢弃Fanout Exchange – 不通过bindingkey路由消息,excha

2016-10-16 15:07:23 316

原创 LeetCode_3 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “

2015-08-03 15:48:24 323

原创 LeetCode_234 Palindrome Linked List

Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space?public boolean isPalindrome(ListNode head) { if(head == null || h

2015-08-03 14:10:29 276

原创 LeetCode_206 Reverse Linked List

Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?pre始终是首元结点的值,每次对pnext重新赋值 递归 public ListNode reverseList(ListNode

2015-08-03 11:34:08 312

原创 LeetCode_237 Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with valu

2015-07-31 11:31:49 295

原创 Leetcode_226 Invert Binary Tree

Invert a binary tree. 4/ \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this original tweet by Max Howell: Go

2015-07-30 18:22:24 265

原创 LeetCode_199 Binary Tree Right Side View

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example: Given the following binary tree, 1

2015-07-30 18:19:01 288

原创 LeetCode_145 Binary Tree Postorder Traversal

Given a binary tree, return the postorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. private void resPreorder(TreeNode

2015-07-30 18:16:19 280

原创 LeetCode_144 Binary Tree Preorder Traversal

Given a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].List<Integer> result = new ArrayList

2015-07-30 18:13:32 340

原创 LeetCode_124 Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example: Given the below binary tree, 1 / \ 2 3Return 6.如果这个作为root,那么最长路应该就是F(left) + F(ri

2015-07-30 11:33:51 281

原创 LeetCode_222 Count Complete Tree Nodes

Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely fill

2015-07-29 17:36:02 315

原创 LeetCode_230 Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST’s total elements. Follow up: What i

2015-07-29 16:33:55 287

原创 LeetCode_129 Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total sum of al

2015-07-29 16:09:46 342

原创 LeetCode_235 Lowest Common Ancestor of a Binary Search Tree

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two

2015-07-29 15:48:35 253

原创 LeetCode_114 Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place.For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like 1 \ 2 \

2015-07-29 11:20:40 241

原创 LeetCode_113 Path Sum II

Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum. For example: Given the below binary tree and sum = 22, 5

2015-07-28 21:52:10 177

原创 LeetCode_112 Path Sum

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. For example: Given the below binary tree and

2015-07-28 20:56:25 250

原创 LeetCode_111 Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.public int minDepth(TreeNode root) {

2015-07-28 17:48:03 242

原创 LeetCode_110 Balanced Binary Tree

Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diff

2015-07-28 17:12:47 265

原创 LeetCode_108 Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.高度平衡是指左右子树的高度最大相差1,二分检索树是,根节点的左子树的所有节点值都小于等于根节点,右子树的所有节点值都大于等于根节点,左右子树也是二分搜索树。 public TreeNode sort

2015-07-28 11:40:03 217

原创 LeetCode_107 Binary Tree Level Order Traversal II

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).For example: Given binary tree {3,9,20,#,#,15,7},

2015-07-28 10:28:11 251

原创 LeetCode_106 Construct Binary Tree from Inorder and Postorder Traversal

Given inorder and postorder traversal of a tree, construct the binary tree.public TreeNode buildTree(int[] inorder, int[] postorder) { int size = inorder.length; if(size ==0) return

2015-07-28 10:03:50 260

原创 LeetCode_105 Construct Binary Tree from Preorder and Inorder Traversal

Given preorder and inorder traversal of a tree, construct the binary tree. public TreeNode buildTree(int[] preorder, int[] inorder) { int size = inorder.length; if(size ==

2015-07-27 18:07:17 270

原创 LeetCode_103 Binary Tree Zigzag Level Order Traversal

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). For example: Given binary

2015-07-15 21:28:12 233

原创 LeetCode_104 Maximum Depth of Binary Tree

Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.可以采用递归,DFS public int maxDepth(T

2015-07-15 17:42:40 247

原创 LeetCode_102 Binary Tree Level Order Traversal

Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). For example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9

2015-07-15 16:56:26 243

原创 LeetCode_101 Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 B

2015-07-15 14:43:55 317

原创 Leetcode_100 Same Tree

Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. public bo

2015-07-15 14:03:15 230

原创 Leetcode_98 Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key.

2015-07-15 10:52:55 242

原创 Leetcode_95 Unique Binary Search Trees II

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-07-14 17:05:42 231

原创 LeetCode_96 Unique Binary Search Trees

Given n, how many structurally unique BST’s (binary search trees) that store values 1…n? For example, Given n = 3, there are a total of 5 unique BST’s. 1 3 3 2 1

2015-07-14 15:30:01 239

原创 Leetcode_94 Binary Tree Inorder Traversal

Given a binary tree, return the inorder traversal of its nodes’ values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2]. Note: Recursive

2015-07-14 14:28:42 285

原创 深入JVM(之一)--Java内存区域与内存溢出异常

Java与C++之间有一睹由内存动态分配和垃圾收集技术所围成的“高墙”,墙外的人想进去,墙内的人想出去。运行时数据区域Java虚拟机在执行Java程序的过程中会把它所管理的内存划分为若干个不同的数据区域,这些数据区域各有用途,以及创建和销毁的时间,有的区域会随着虚拟机进程的启动而存在,有的区域则依赖用户线程的启动和结束而建立和销毁。Java虚拟机所管理的内存将会包括以下几个运行时数据区域程序计数器

2015-07-08 22:14:46 354

原创 Struts(之一)--基本介绍

MVC思想MVC并不是Java语言所特有的设计思想,它是所有面向对象程序设计语言都应该遵守的思想。 MVC思想将一个应用分成三个基本部分:Model(模型)、View(视图)和Controller(控制器)。这三部分以最少的耦合协同工作,从而提高应用的可扩展性和可维护性。 MVC思想类似于观察者模式,但又有区别:观察者模式下观察者和被观察者可以是两个互相等的对象,但MVC被观察者往往只是单纯的数

2015-07-07 13:24:34 326

原创 Hibernate(之一)--基本介绍

Hibernate是轻量级Java EE应用的持久层的解决方案,Hibernate不仅管理Java类到数据库表的映射(包括Java数据类型到SQL数据类型的映射),还提供数据查询和获取数据的方法,可以大幅度缩短处理数据持久化时间。 Hibernate较之另一个持久层框架MyBatis,Hibernate更具有面向对象的特征:受Hibernate的影响,JavaEE规范抛弃了传统的Entity EJ

2015-07-06 21:01:00 478

空空如也

空空如也

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

TA关注的人

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