自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 mybatis查询返回map的问题

文章目录背景1、mybatis只返回单个map2、查询返回map的list3、利用mybatis的@MapKey注解返回map4、重写handler背景假设背景:想获取某个省下各个市有多少问题,以Map<String, Integer> 的形式返回,key 代表某个市的问题个数数据库表为:prov_code varchar 代表省的编码city_code varchar 代表市的编码problem varchar 代表拥有的某个问题所以有一条该市的数据就说明该市多了

2021-11-23 11:16:08 25850 1

原创 18、删除链表中重复的节点

/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode deleteDuplication(ListNode pHead

2018-05-02 15:26:09 232

原创 20、表示数值的字符串

public class Solution { public boolean isNumeric(char[] str) { String s=String.valueOf(str); //? 出现一次或零次 //+ 至少出现一次 //* 出现任意多次 //\\ 后面接特殊字符不转义 //[

2018-05-02 14:42:36 241

原创 19、正则表达式匹配

整体思路:当模式中的第二个字符不是“*”时: 1、如果字符串第一个字符和模式中的第一个字符相匹配,那么字符串和模式都后移一个字符,然后匹配剩余的。 2、如果 字符串第一个字符和模式中的第一个字符相不匹配,直接返回false。而当模式中的第二个字符是“*”时: 如果字符串第一个字符跟模式第一个字符不匹配,则模式后移2个字符,继续匹配。如果字符串第一个字符跟模式第一个字符匹配,可以有3种匹配方式:

2018-05-02 11:07:49 276

原创 36、二叉搜索树与双向链表

整体思路: 函数f对该树排序,返回值为链表的头节点 f(左子树) 将左子树最后一个结点和root连接 f(右子树) 将右子树头结点和root连接public class Solution { public TreeNode Convert(TreeNode pRootOfTree) { if(pRootOfTree==null) return pRootOfT...

2018-05-01 16:47:44 138

原创 38、字符串的排列

import java.util.ArrayList;import java.util.HashSet;public class Solution { public ArrayList&lt;String&gt; Permutation(String str) { ArrayList&lt;String&gt; result = new ArrayList&lt;Str...

2018-05-01 16:44:10 211

原创 40、最小的k个数

import java.util.ArrayList;public class Solution { public ArrayList&lt;Integer&gt; GetLeastNumbers_Solution(int [] input, int k) { ArrayList&lt;Integer&gt; dui = new ArrayList&lt;Integer&...

2018-04-28 16:15:35 121

原创 43、1-n整数中1出现的次数

整体思路: 该位为0,该位大于1,该位等于1,分开处理public class Solution { public int NumberOf1Between1AndN_Solution(int n) { int result = 0; int m = 0; int s = 0; while(n!=0) {...

2018-04-28 15:43:41 118

原创 59、滑动窗口的最大值

1、滑动窗口的最大值 思路: deque中只保存可能会是最大值的数,每新加入一个数,就把队列中比该数大的数全部删除,因为前面的数已经不可能成为最大数import java.util.ArrayDeque;import java.util.ArrayList;public class Solution { public ArrayList<Integer> maxInWindows(i

2018-04-20 16:47:32 136

原创 41、数据流中的中位数

思路: 前一半数用最大堆保存,后一半数用最小堆保存,并且最大堆的所有数小于最小堆的所有数,这样求中位数就是当最大堆最小堆堆顶的和的一半。import java.util.ArrayList;public class Solution { ArrayList<Integer> max = new ArrayList<Integer>(); ArrayList<Integer> mi

2018-04-18 10:09:50 217 1

原创 51、数组中的逆序对

思路: 利用归并排序的思想,先对前一半数组统计逆序对后从小到大排序,再对后一半数组统计逆序对后排序,再统计前后两个数组之间的逆序对。用空间换时间。import java.util.Arrays;public class Solution { public int InversePairs(int [] array) { if((array==null) ||(ar...

2018-04-16 10:53:01 228

原创 35、复杂链表的赋值

public RandomListNode Clone(RandomListNode pHead) { if(pHead==null) return null; //将新链表每个节点插在旧链表对应的每个节点后面 RandomListNode oldNode = pHead; while(oldNode!=null)

2018-04-16 09:46:10 166

原创 排序(二)堆排序、归并排序、快速排序

本文是是时间复杂度为O(nlogn)的排序算法堆排序思路:(以最大堆举例) 将数组array变成最大堆,array[0]则为数组中的最大数,调换array[0]和array[i](i为未排序的数组的末尾)。然后逐步减小i,即array[0]到array[i]为未排序的数组。先确定数组的末尾。public class mysort { public void sort(...

2018-04-15 16:51:26 275

原创 排序算法(一)冒泡排序,简单选择排序,直接插入排序,希尔排序

冒泡排序

2018-04-13 16:54:17 918

原创 自己实现queue、stack

1、用数组实现的stack,包括动态调整大小,可迭代,泛型import java.util.*;public class arraystack<item> implements Iterable<item> { private item[] stack = (item[])new Object[1]; private int sizes=0; private void res

2018-04-13 10:57:02 282

原创 50、第一个只出现一次的字符

题目一:字符串中第一个只出现一次的字符import java.util.ArrayList;import java.util.HashMap;import java.util.Map;public class Solution { public char f(String s) { if(s.length()==0) return ' ';

2018-04-12 21:10:20 104

原创 45、把数组排成最小的数

import java.util.Arrays;import java.util.Comparator;public class Solution { public String PrintMinNumber(int [] numbers) { if(numbers.length==0) return ""; String[] num = new Stri

2018-04-12 15:48:40 138

原创 9、两个栈实现队列

题目一:用两个栈实现一个队列 解法一:stack1永远用作存放元素,stack2在pop时作为转换工具import java.util.Stack;public class Solution { Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2 = new Stack<Integer>();

2018-04-12 10:15:33 111

原创 11、旋转数组的最小数字

1、遇到的第一个比前一个数字小的数就是result,不存在就是array[0]是resultpublic class Solution { public int minNumberInRotateArray(int [] array) { if(array.length==0) return 0; int num = array[0]; for

2018-04-11 23:50:15 138

原创 主题提取LDA方法

此处用fetch_20newsgroups数据训练import gensimfrom sklearn.datasets import fetch_20newsgroupsfrom gensim.utils import simple_preprocessfrom gensim.parsing.preprocessing import STOPWORDSfrom gensim.corpora

2018-04-11 18:08:02 10982 2

原创 二叉搜索树

二叉搜索树需满足以下四个条件:若任意节点的左子树不空,则左子树上所有结点的值均小于它的根结点的值;若任意节点的右子树不空,则右子树上所有结点的值均大于它的根结点的值;任意节点的左、右子树也分别为二叉查找树;没有键值相等的节点。二叉搜索树的特点: 1、中序遍历一定是从小到大排列总体思路:先访问根,比根小访问左结点,比根大访问右节点public class searchTree { T

2018-04-10 11:35:43 176

原创 31、栈的压入、弹出序列

import java.util.ArrayDeque;public class Solution { public boolean IsPopOrder(int [] pushA,int [] popA) { if((pushA.length<=0) || (popA.length<=0)) return false; ArrayDeque<Integer

2018-04-10 10:32:43 97

原创 5、替换空格

public class Solution { public String replaceSpace(StringBuffer str) { if(str.length()&lt;=0) return str.toString(); int spaceCount = 0; String result; StringBuffer...

2018-04-09 20:53:05 88

原创 62、圆圈中最后剩下的数字

1、简便方法,通过删去第一个数找递归关系public class Solution { public int LastRemaining_Solution(int n, int m) { if((n&lt;1) || (m&lt;1)) return -1; int result = 0; for(int i=2;i&lt;=n;i++)...

2018-04-09 20:16:03 171

原创 61、扑克牌中的顺子

import java.util.Arrays;public class Solution { public boolean isContinuous(int [] numbers) { //考虑输入为空的情况 if(numbers.length==0) return false; Arrays.sort(numbers); ...

2018-04-09 19:30:07 167

原创 7、重建二叉树

import java.util.Arrays;/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public c...

2018-04-09 16:54:00 91

原创 54、二叉搜索树的第k大结点

/*public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public class Solution { TreeNode resu

2018-04-09 10:26:01 87

原创 33、二叉搜索树的后序遍历序列

import java.util.Arrays;public class Solution { public boolean VerifySquenceOfBST(int [] sequence) { if(sequence.length&lt;=0) return false; //[0,index])左子树,[index,sequence.length...

2018-04-09 10:02:22 91

原创 26、树的子结构

/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public class Solution { public boole

2018-04-08 17:17:43 84

原创 34、二叉树中和为某一值的路径

1、按照前序遍历import java.util.ArrayList;import java.util.ArrayDeque;/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { ...

2018-04-08 17:17:10 99

原创 55、二叉树的深度

1、题目一:求二叉树的深度/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public class Solution {

2018-04-08 10:23:30 118

原创 37、序列化二叉树

/*public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public class Solution { int i=...

2018-04-04 16:48:02 116

原创 32、从上到下打印二叉树

1、题目一:不分行从上到下打印二叉树import java.util.ArrayList;import java.util.ArrayDeque;/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(in...

2018-04-04 15:08:30 101

原创 28、对称的二叉树

/*public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public class Solution { boolea...

2018-04-04 10:18:10 104

原创 8、二叉树的下一个节点

/*public class TreeLinkNode { int val; TreeLinkNode left = null; TreeLinkNode right = null; //父节点 TreeLinkNode next = null; TreeLinkNode(int val) { this.val = val; }

2018-04-03 17:05:46 117

原创 27、二叉树的镜像

1、递归的方法将根节点的左右子树对调,再将左右子树的左右子树对调,依次递归/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val;...

2018-04-03 16:27:10 109

原创 4、二维数组中的查找

public class Solution { public boolean Find(int target, int [][] array) { if(array.length<1) return false; int rows = array.length; int cols = array[0].length; //从右上

2018-03-30 20:11:54 96

原创 3、数组中重复的数字

1、利用哈希表,时间为O(n),但是牺牲了O(n)的空间 2、修改原数组,时间为O(n),空间为O(0)public class Solution { // Parameters: // numbers: an array of integers // length: the length of array numbers //

2018-03-30 19:39:04 97

原创 13、机器人的运动范围

public class Solution { public int count = 0; public int movingCount(int threshold, int rows, int cols) { boolean[] visited = new boolean[rows*cols]; for(int k=0;k<rows*cols;

2018-03-30 17:23:49 160

原创 12、矩阵中的路径

public class Solution { boolean hasPath = false; public boolean hasPath(char[] matrix, int rows, int cols, char[] str) { //对矩阵的每个点进行search,查到了路径就返回true for(int i=0;i<rows;i++)

2018-03-30 14:33:36 225

空空如也

空空如也

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

TA关注的人

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