自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 股票的最大利润(Java实现)

public class E63MaxProfit { //股票的最大利润 public static int getMaxProfit(int[] numbers, int length){ if (numbers == null || length < 2) return 0; int min = numbers...

2019-11-12 20:02:47 1310

原创 圆圈中最后剩下的数字(Java实现)

public class E62LastRemainNumber { //圆圈中最后剩下的数字 /*解法一:构造环形链表*/ static class ListNode<T> { //环形链表节点 T value; ListNode<T> nextNode; ListNode(T ...

2019-11-12 20:02:05 176

原创 剑指offer第60题:n个骰子的点数(Java实现)

public class E60Probability { //剑指offer第60题:n个骰子的点数 /*打印出和为s的所有可能值及其概率*/ public static void printProbility(int number) { /*维护两个数组,通过前一个数组的值计算下一个数组的值*/ final int MAX_VALUE = ...

2019-10-31 21:30:41 215

原创 队列的最大值(Java实现)

import java.util.*;public class E59MaxInQueue { //队列的最大值 /*问题一:滑动窗口的最大值*/ public static Queue<Integer> getMaxInWindows(int[] queue, int windowsSize) { if (queue == null |...

2019-10-29 21:43:20 1055

原创 翻转字符串(Java实现)

public class E58ReverseString { //翻转字符串 /*问题一:翻转句子但单词内部不翻转*/ public static String reverseString(String str){ if (str == null) return null; char[] chars = str....

2019-10-28 21:03:24 299

原创 和为s的数字(Java实现)

public class E57NumbersWithSum { //和为s的数字 /*问题一:在递增数组中寻找和为s的两个数字*/ public static void findTwoNumbers(int[] numbers, int s){ if (numbers == null || numbers.length < 2) ...

2019-10-28 21:02:14 137

原创 数组中数字出现的次数(Java实现)

public class E56NumbersAppearOnce { //数组中数字出现的次数 /*问题一:两个只出现一次的数字+出现两次的其它数字*/ public static void findNumbers(int[] numbers, int length) { if (numbers == null || length <= 1) ...

2019-10-23 21:17:43 742

原创 二叉树的深度&判断是否为平衡二叉树(Java实现)

public class E55TreeDepth { //二叉树的深度 /*问题一:二叉树的最长路径*/ public static int getTreeDepth(BinaryTreeNode root) { if (root == null) return 0; int left = getTreeDept...

2019-10-23 21:16:18 156

原创 二叉搜索树的第K大节点(Java实现)

public class E54KthBSTNode { //二叉搜索树中第k个节点 private static int index; public static BinaryTreeNode getKthNode(BinaryTreeNode root, int k){ if (root == null) return null...

2019-10-22 20:36:02 383

原创 在排序数组中查找数字(Java实现)

public class E53FindInNumbersInOrder { //在排序数组中查找数字 /*问题一:数字在数组中出现的次数*/ public static int getTimes(int[] numbers, int length, int target) { int times = -1; if (numbers !=...

2019-10-22 20:34:13 274

原创 两个链表的第一个公共节点(Java实现)

public class E52FirstCommonListNode { //两个链表的第一个公共节点 private static class ListNode { int value; ListNode nextNode; } public static ListNode find(ListNode root1, ListN...

2019-10-22 20:31:25 197

原创 数组中的逆序对(Java实现)

public class E51CountInversePairs { //数组中逆序对的数量 public static int inversePairs(int[] data, int length) { if (data == null || length <= 0) return -1; int[] copy...

2019-10-16 21:14:11 281

原创 第一个只出现一次的字符(Java实现)

import java.util.HashMap;public class E50FirstNonredundantChar { //第一个不重复的字符 /*问题一:字符串中第一个不重复的字符*/ public static String getChar(String str){ if (str == null || str.length() == 0...

2019-10-16 21:13:13 123

原创 丑数(Java实现)

import static jdk.nashorn.internal.objects.NativeMath.min;public class E49UglyNumber { //找到第n个丑数,视1为第一个丑数 public static int getUglyNumber(int index){ if (index <= 0) ...

2019-10-12 21:03:46 214

原创 最长不含重复字符的子字符串(Java实现)

public class E48LongestSubstringWithoutDuplication { //最长不含重复字符的子字符串 public static int count(String str){ //记录返回值 int maxLength = 0; //记录当前长度 int currentLength...

2019-10-12 21:02:30 395

原创 礼物的最大价值(Java实现)

public class E47MaxValueOfGifts { //礼物的最大价值 public static int getMaxValue_Solution1(int[] value, int rows, int cols){ if (value == null || (rows <= 0 && cols <= 0)) ...

2019-10-10 20:46:29 665

原创 把数字翻译成字符串(Java实现)

public class E46Translation { //计算数字的翻译方式,1-'a'... 25-'z' public static int getTranslationCount(int number) { if (number < 0) return -1; char[] numbers = Stri...

2019-10-10 20:45:52 319

原创 把数组排成最小的数(Java实现)

import java.util.Arrays;import java.util.Comparator;public class E45SplicingToBeMin { //将数组中的数字拼接成最新小的数字 public static String splicing(int[] numbers, int length){ if (numbers == n...

2019-10-10 20:44:58 115

原创 数字序列中某一位的数字(Java实现)

public class E44findDigitInSequence { //数字序列中某一位的数字 public static int digitAtIndex(int index){ if (index < 0) return -1; int digits = 1; while(true){...

2019-10-08 21:28:23 225

原创 1~n整数中1出现的次数(Java实现)

public class E43NumberOf1Between1AndN { //1-N整数中含1的个数 public static int numberOf1(int n){ //时间复杂度为NO(log(N)) if (n <= 0) return -1; int count = 0; for ...

2019-10-08 21:27:41 170

原创 连续子数组的最大和(Java实现)

import java.util.LinkedList;import java.util.List;public class E42GreatestSumOfSubArray { //找出数组中连续子数组的最大和 //动态规划思想:max(f(data[i])),f(data[i])为以第i个元素结尾的连续子数组之和 public static int getGr...

2019-10-06 21:24:45 142

原创 数据流中的中位数(Java实现)

import java.util.Comparator;import java.util.PriorityQueue;public class E41MedianOfDynamicArray<T extends Number> { //最小优先队列及最大优先队列 private PriorityQueue<T> min = new PriorityQ...

2019-10-06 21:20:34 193

原创 最小的k个数(Java实现)

import java.util.PriorityQueue;public class E40LeastKNumbers { //最小的K个数,利用大小为k的优先队列 public static void findLeastNumbers(int[] numbers, int length, int k){ if (numbers == null || le...

2019-10-04 20:36:24 167

原创 数组中出现超过一半的数字(Java实现)

public class E39MoreThanHalfNum { //数组中出现次数超过一半的数字 public static int getNumber(int[] numbers, int length){ if (numbers == null || length <= 0) throw new IllegalArgumen...

2019-10-04 20:35:37 152

原创 字符串的排列(Java实现)

public class E38Permutation { //打印字符串中字符的全排列 //将字符串分为第一个字符和剩下地字符两部分 public static void permutation(String str){ if (str == null) return; char[] chars = str.toC...

2019-10-03 20:00:53 74

原创 InnoDB与MyISAM存储引擎的比较

MySQL中拥有多种存储引擎,其中InnoDB是默认的数据引擎,现将其与MyISAM存储引擎对比:是否支持事务:InnoDB支持,MyISAM不支持。用途:InnoDB主要用于在线事务处理(OLTP)应用,而MyISAM主要用于在线分析处理(OLAP)应用。支持的锁类型:InnoDB支持行锁与表锁,而MyISAM只支持表锁。缓存:MyISAM只缓存索引文件,而不缓存数据文件,通过操作系统...

2019-10-02 17:56:58 145

原创 二叉搜索树与双向链表(Java实现)

一、实现public class E36ConvertBSTToDeque { //将二叉搜索树转化为双向链表 private static class BinaryTreeNode{ int value; BinaryTreeNode left; BinaryTreeNode right; } private...

2019-09-30 21:31:53 97

原创 复杂链表的复制(Java实现)

public class E35CloneComplexListNode { //复杂链表的复制 //利用哈希表可以用空间换时间,或者分三步复制链表 private static class ComplexListNode{ //复杂链表结构 int value; ComplexListNode next; ...

2019-09-30 19:51:27 233

原创 二叉搜索树中和为某一值的路径(Java实现)

import java.util.Iterator;import java.util.LinkedList;public class E34FindPathDependOnSum { //二叉树中和为某一值的路径 private static class BinaryTreeNode{ int value; BinaryTreeNode le...

2019-09-28 20:50:02 144

原创 二叉搜索树的后序遍历序列(Java实现)

public class E33VerifySequenceOfBST { //判断某一序列是否是二叉搜索树的后序遍历序列 private class BinaryTreeNode{ int value; BinaryTreeNode left; BinaryTreeNode right; } public sta...

2019-09-28 20:48:36 98

原创 从上到下打印二叉树(Java实现)

问题描述从上到下打印如下结构的二叉树:private static class BinaryTreeNode{ int value; BinaryTreeNode left; BinaryTreeNode right;}问题一: 不分行从上到下打印二叉树public static void printFromTopToButton(BinaryTreeNode r...

2019-09-27 21:59:00 242

原创 栈的压入、弹出序列(Java实现)

import java.util.Stack;public class E31PushPopSequence { //根据入栈序列判断出栈序列是否正确 public static boolean isPopOrder(int[] push, int[] pop, int length){ if (push == null || pop == null || l...

2019-09-25 20:37:35 158

原创 包含min函数的栈

import java.util.Stack;public class E30StackForMin<T extends Comparable<T>> { //实现一个包含min函数的栈,push,pop,min操作的时间复杂度都为O(1) //辅助栈顶始终保存当前栈高度对应的栈中最小值 private Stack<T> store...

2019-09-25 20:35:33 66

原创 顺时针打印矩阵(Java实现)

public class E29PrintMatriClockwisely { //顺时针打印矩阵 public static void printMatriClockwisely(int[][] numbers, int rows, int cols){ //将整个矩阵一圈一圈打印,起点的横纵坐标值相等 if (numbers == null ...

2019-09-25 20:34:35 130

原创 对称的二叉树(Java实现)

public class E28SymmetricalBinaryTree { //判断是否为对称二叉树,采用对称的二叉树遍历方法 private class BinaryTreeNode{ int value; BinaryTreeNode leftNode; BinaryTreeNode rightNode; } ...

2019-09-25 20:33:34 102

原创 二叉树的镜像(Java实现)

public class E27MirrorBinaryTree { //二叉树的镜像 private class BinaryTreeNode{ int vallue; BinaryTreeNode leftNode; BinaryTreeNode rightNode; } public static void...

2019-09-23 20:45:41 99

原创 树的子结构(Java实现)

public class E26Subtree { //树的子结构 private class BinaryTreeNode{ //比较时要注意在精度范围内比较 double value; BinaryTreeNode leftNode; BinaryTreeNode rightNode; } p...

2019-09-23 20:44:51 89

原创 合并两个排序的链表(Java实现)

public class E25MergeOrderedList { //合并两个排序的链表 private class ListNode{ int value; ListNode nextNode; } public static ListNode mergeOrderedList(ListNode head1, ListNo...

2019-09-22 17:05:47 370

原创 反转链表(Java实现)

public class E24ReverseList { //反转链表 private class ListNode{ int value; ListNode nextNode; } public static ListNode reverseList(ListNode head){ ListNode reve...

2019-09-22 17:04:36 76

原创 链表中环的入口节点(Java实现)

public class E23FindEntryFromLoop { //链表中环的入口节点 private class ListNode{ int value; ListNode nextNode; } public static ListNode entryNodeOfLoop(ListNode head){ ...

2019-09-19 20:42:06 141

空空如也

空空如也

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

TA关注的人

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