自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Java使用DBCP连接池

DBCP 是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件。单独使用dbcp需要3个包:common-dbcp.jar,common-pool.jar,common-collections.jar。package cn.com.***;import com.google.gson.Gson;import org.apache.commons.dbcp2

2016-08-22 14:41:58 577

原创 Apache Thrift - java开发教程

1.开发所需要的jar包: org.apache.thrift libthrift 0.9.0 org.slf4j slf4j-api 1.7.12 2. 安装Thrift环境

2016-07-29 15:33:55 503

原创 Sort a Map<Key, Value> by values (Java) HashMap按value值排序

对HashMap按value值的大小进行排序,方法如下。import java.util.*;public class MapUtil{ public static > Map sortByValue( Map map ) { List> list = new LinkedList>( map.entrySet() )

2016-07-12 17:35:44 2286

原创 JAVA解析EXCEL文件

首先,需要导入POI包。        1.解析.xlsx后缀名的的EXCEL文件:package com.shuai.hello;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import org.apache.poi.hssf.usermodel.HS

2016-07-07 14:56:40 5582 1

原创 1

@WebServlet(name="UploadServlet",urlPatterns="/UploadServlet")@MultipartConfig//标识Servlet支持文件上传public class UploadServlet extends HttpServlet { public void doGet(HttpServletRequest request, Http

2015-11-11 22:42:55 442

原创 JAVA中的优先级队列PriorityQueue

优先级队列是不同于先进先出队列的另一种队列。每次从队列中取出的是具有最高优先权的元素。PriorityQueue是从JDK1.5开始提供的新的数据结构接口。如果不提供Comparator的话,优先队列中元素默认按自然顺序排列,也就是数字默认是小的在队列头,字符串则按字典序排列。import java.util.Comparator;import java.util.PriorityQ

2015-09-18 17:38:42 429

原创 Java多线程

线程:表示程序的执行流程,是CPU调度执行的基本单位;线程有自己的程序计数器、寄存器、堆栈和帧。同一进程中的线程共用相同的地址空间,同时共享进进程锁拥有的内存和其他资源。JAVA多线程实现方式主要有三种:继承Thread类、实现Runnable接口、使用ExecutorService、Callable、Future实现有返回结果的多线程。其中前两种方式线程执行完后都没有返回值,

2015-09-02 17:54:14 386

原创 JAVA查询Oracle数据库导出成txt文本

import java.io.FileOutputStream;import java.io.PrintStream;import java.sql.Statement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLExcepti

2015-08-12 15:41:37 4766 1

原创 MySQL SQL优化

前言有人反馈之前几篇文章过于理论缺少实际操作细节,这篇文章就多一些可操作性的内容吧。注:这篇文章是以 MySQL 为背景,很多内容同时适用于其他关系型数据库,需要有一些索引知识为基础。 优化目标  1.减少 IO 次数  IO永远是数据库最容易瓶颈的地方,这是由数据库的职责所决定的,大部分数据库操作中超过90%的时间都是 IO 操作所占用的,减少 I

2015-05-06 09:28:02 643

原创 Leetcode:Longest Palindromic Substring

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.基本思路:回文字符串显然有个特征是沿

2015-04-26 14:58:02 650

原创 Leetcode:Set Matrix Zeroes

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.遍历矩阵,如果遇到等于0的元素,则把该元素所在行的第一个元素和所在列第一个元素置为0。考虑到row0和col0会重合,所以另外设置一个变量col0来表示第一列的情况。然后从左下角开始,把符合条件的元素置

2015-04-23 12:28:15 575

原创 Leetcode:Palindrome Partitioning

Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","

2015-04-08 13:43:37 497

原创 二叉树的前序,中序及后续遍历

前序遍历:先访问跟结点,然后遍历左子树,最后遍历右子树。即“根左右”。实现代码:class Solution {public: vector preorderTraversal(TreeNode *root) { if (root==NULL) { return vector(); } vector resu

2015-04-07 15:45:36 591

原创 Leetcode:Binary Search Tree Iterator

Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()

2015-04-07 12:37:39 437

原创 二叉树的层序遍历

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 20

2015-03-31 13:23:04 635

原创 Leetcode:Populating Next Right Pointers in Each Node

Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.

2015-03-29 18:06:48 382

原创 Json转换利器Gson——简单对象转化和带泛型的List转化

Gson 是 Google 提供的用来在 Java 对象和 JSON 数据之间进行映射的 Java 类库。可以将一个 JSON 字符串转成一个 Java 对象,或者反过来。先下载对应jar包:gson-1.6.jar实体类:[java] view plaincopypublic class Student {      priva

2015-03-27 12:27:27 727

原创 LeetCode:Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]

2015-03-26 21:49:54 411

原创 通过Servlet创建服务器端JSON数据

服务端提供JSON数据接口:http://localhost:8080/JSONInterface/servlet/jsservlet首先要导入项目所需要的jar包。package com.shuai.JsonManager;import java.io.IOException;import java.io.PrintWriter;import java.util.HashMap;

2015-03-26 15:34:57 2366

原创 LeetCode:Jump Game

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.Determine i

2015-03-25 20:34:21 450

原创 二叉树的深度优先和广度优先遍历

深度优先搜索算法(Depth First Search),是搜索算法的一种。是沿着树的深度遍历树的节点,尽可能深的搜索树的分支。当节点v的所有边都己被探寻过,搜索将回溯到发现节点v的那条边的起始节点。这一过程一直进行到已发现从源节点可达的所有节点为止。如果还存在未被发现的节点,则选择其中一个作为源节点并重复以上过程,整个进程反复进行直到所有节点都被访问为止。二叉树的深度优先遍历和先序遍

2015-03-20 10:18:02 783

原创 Leetcode:Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 思路:Beca

2015-02-18 16:34:44 626

原创 Leetcode:Largest Number

Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve

2015-02-17 12:49:53 645

原创 Leetcode:Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of

2015-02-13 01:38:47 505

原创 Leetcode:Insertion Sort List

Sort a linked list using insertion sort.插入排序:每步将一个待排序的纪录,按其关键码值的大小插入前面已经排序的文件中适当位置上,直到全部插入完为止。实现代码:class Solution{public: ListNode *insertionSortList(ListNode *head) { if(head=

2015-02-11 20:43:10 535

原创 Leetcode: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 / 3return [1,2,3].Note: Recursive soluti

2015-02-11 00:14:02 556

原创 Leetcode: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-02-10 00:35:50 844

原创 Leetcode:Partition List

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.You should preserve the original relative order of the nodes in each of

2015-02-07 14:13:58 543

原创 Leetcode:Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

2015-02-07 01:01:58 538

原创 Leetcode:Gas Station

There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to

2015-02-05 15:20:17 504

原创 Leetcode:Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element

2015-02-04 22:20:59 373

转载 JAVA-组合与继承

设计原则:多用组合,少用继承。     组合和继承,都能实现对类的扩展。区别如下表所示:组合继承has-a关系is-a关系运行期决定编译期决定不破坏封装,整体和局部松耦合破坏封装,子类依赖父类支持扩展,随意增加组合类只能继承一个父类,必须包含所有方法,

2014-12-29 13:12:08 699

原创 Leetcode:Multiply Strings

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-12-17 15:50:25 445

原创 Leetcode:Single Number II

Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi

2014-12-15 21:25:24 560

原创 Java操作MySQL数据库实现增删查改操作

要用到的jar包:mysql-connector-java-5.1.16-bin.jar,自行到网上下载即可。    根据实际配置数据库的信息: private String dbDriver = "com.mysql.jdbc.Driver"; private String dbUrl = "jdbc:mysql://[ip地址]:[端口号]/[数据库名]";//数据库的信息,根据

2014-12-15 15:16:21 1079

原创 Leetcode:Word Break

Word Break: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.For example, givens = "leetcode"

2014-12-12 19:47:37 504

原创 Leetcode:Valid Sudoku

Valid Sudoku:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.点击打开链接The Sudoku board could be partially filled, where empty cells are filled with the character '.'.

2014-12-09 18:01:19 421

原创 Leetcode:3Sum Closest

3Sum Closest: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that eac

2014-12-07 23:00:30 529

原创 Leetcode:Word Search

Word Search:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizo

2014-12-05 16:26:14 610

原创 Leetcode:Path Sum与Path Sum II

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 binar

2014-12-01 14:20:03 441

空空如也

空空如也

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

TA关注的人

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