自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(1085)
  • 资源 (3)
  • 收藏
  • 关注

原创 72. 编辑距离

class Solution { public int minDistance(String word1, String word2) { if (word1 == null || word2 == null) return 0; char[] cs1 = word1.toCharArray(); char[] cs2 = word2.toCharArray(); int[][] dp = new int[cs1.lengt...

2021-05-13 21:59:44 99

原创 点击列表中的哪一项, 那么该项的文字变成红色

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style> .active { color: red; } </style></head><body><div id="app"> <ul&gt.

2021-05-07 20:38:50 148

原创 RestTemplate 具备负载均衡的能力 —— 相关代码

RestConfig.javapackage com.tuling.mall.userconsumer.config;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.cloud.client.loadbalancer.LoadBalanced;import org.springframework.cloud.client.loadbalancer.LoadBalan

2021-04-07 23:13:31 108

原创 xshell突然连接不上虚拟机解决办法

xshell突然连接不上虚拟机解决办法,重启网络,三个命令:systemctl stop NetworkManagersystemctl disable NetworkManagersystemctl restart network在虚拟机终端命令行中运行后,可以重新连接xshell。

2021-03-27 14:01:02 841

原创 146. LRU 缓存机制

class LRUCache { class Node{ public int key; public int value; public Node prev; public Node next; public Node(){} public Node(int key,int value){ this.key=key; this.value=value;.

2021-11-16 13:16:14 1044

原创 23. 合并K个升序链表

class Solution { public ListNode mergeKLists(ListNode[] lists) { if(lists==null||lists.length==0) return null; for(int i=1;i<lists.length;i++){ lists[i]=mergeTwoLists(lists[i],lists[i-1]); } return lists[.

2021-10-13 18:30:57 739

原创 约瑟夫环的问题--剑指 Offer 62. 圆圈中最后剩下的数字

class Solution { // f(n, m) = (f(n – 1, m) + m) % n public int lastRemaining(int n, int m) { return (n == 1) ? 0 : (lastRemaining(n - 1, m) + m) % n; }}

2021-09-29 21:58:32 784

原创 50. Pow(x, n)

class Solution { // T(n) = T(n/2) + O(1) = O(logn) public double myPow(double x, int n) { if (n == 0) return 1; if (n == -1) return 1 / x; double half = myPow(x, n >> 1); half *= half; // 是否为奇数 .

2021-09-29 20:00:32 151

原创 99. 恢复二叉搜索树

root 是一棵错误的二叉搜索树(有2个节点被错误交换)发生在逆序对的头,尾这两个位置第2个错误节点:最后一个逆序对中较小的那个节点 second/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val

2021-09-25 00:33:39 94

原创 234.回文链表(判断一个链表是不是回文链表)

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } *...

2021-08-21 21:18:54 129

原创 1. 两数之和

class Solution { public int[] twoSum(int[] nums, int target) { if (nums == null) return null; Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < nums.length; i++) { Integer idx = map.g...

2021-08-18 17:43:32 129

转载 atomic底层实现是基于无锁算法cas

CAS 算法解析图什么叫偏移量?要用cas修改某个对象属性的值->,首先要知道属性在对象的内存空间的哪个位置,必须知道属性的偏移量UnsafeInstance.javapackage com.dym.utils;import sun.misc.Unsafe;import java.lang.reflect.Field;public class UnsafeInstance { public static Unsafe reflectGetUns...

2021-08-03 21:08:47 152

原创 AtomicInteger 的用法----》》既能保证线程安全又能保证效率

package com.dym.atomic;import java.util.concurrent.CountDownLatch;import java.util.concurrent.atomic.AtomicInteger;public class T1_AtomicInteger { public static int total = 0; static AtomicInteger atomic = new AtomicInteger(0); public s.

2021-08-03 20:22:22 151

原创 ForkJoinPool---ForkJoinTask

import java.util.concurrent.*;class MyTask extends RecursiveTask<Integer> { //拆分差值不能超过10,计算10以内运算 private static final Integer VALUE = 10; private int begin ;//拆分开始值 private int end;//拆分结束值 private int result ; //返回结果 ...

2021-07-26 21:58:16 176

原创 RocketMQ-- 一对多 (消费者与生产者)

Producer.javapackage com.dym.one2many;//发送消息import org.apache.rocketmq.client.exception.MQBrokerException;import org.apache.rocketmq.client.exception.MQClientException;import org.apache.rocketmq.client.producer.DefaultMQProducer;import org.apache

2021-07-16 20:16:28 789

原创 RocketMQ--生产者与消费者的简单示例

pom.xml<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache..

2021-07-16 19:41:28 508

原创 数据库的小知识——主从架构

主从架构是前提读写分离主从切换都是需要中间件去处理的但是前提的条件就是首先需要搭建主从架构的mysql的集群

2021-07-12 22:19:36 170

原创 155. 最小栈

设计一个支持push,pop,top操作,并能在常数时间内检索到最小元素的栈。class MinStack { /* 用来存放正常数据 */ private Stack<Integer> stack; /* 用来存放最小数据 */ private Stack<Integer> minStack; /** initialize your data structure here. */ public MinStack() { ...

2021-07-03 17:44:52 102

原创 141. 环形链表—— 快慢指针的思想

/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public boolean hasCycle(ListNode head)...

2021-06-27 15:06:30 133

原创 206. 反转链表

使用递归的方式/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = n..

2021-06-27 14:49:11 119

原创 237. 删除链表中的节点

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public void deleteNode(ListNode node) { node.val = node.next.val; node.next = n...

2021-06-27 14:12:33 89

原创 动态代理(JDK的动态代理)

UsbSell.javapackage com.dym.service;//目标接口public interface UsbSell { float sell(int amount); void print();}UsbKingFactory.javapackage com.dym.factory;import com.dym.service.UsbSell;//目标类public class UsbKingFactory implements Us..

2021-06-20 18:31:34 136

原创 计算页数的公式

每一页显示100条数据, pageSize一共有999999条数据, n请问有多少页 pageCount = (n + pageSize - 1) / pageSize

2021-06-19 21:21:13 2708

原创 86. 分隔链表

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; }...

2021-06-19 14:51:35 101

原创 160. 相交链表

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode getIntersecti...

2021-06-19 14:28:23 64

原创 2. 两数相加

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; }...

2021-06-19 13:53:52 91

原创 203. 移除链表元素

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; }...

2021-06-19 13:30:43 81

原创 链表题的解题思路

2021-06-19 11:44:39 80

原创 16.16. 部分排序

class Solution { public int[] subSort(int[] nums) { if (nums.length == 0) return new int[] { -1, -1 }; // 从左扫描到右寻找逆序对(正序:逐渐变大) int max = nums[0]; // 用来记录最右的那个逆序对位置 int r = -1; for (int i = 1; i < nums.length; i...

2021-06-19 11:29:11 95

原创 75. 颜色分类

/* * 一个只包含0、1、2的整型数组,要求对它进行【原地】排序 * 你能想出一个仅使用常数空间的一趟扫描算法吗? * * 空间复杂度O(1),时间复杂度O(n) */class Solution { public void sortColors(int[] nums) { int i = 0; int l = 0; int r = nums.length - 1; while (i <= r) { if (n...

2021-06-19 10:44:58 71

原创 88. 合并两个有序数组

class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { // nums1 = [1,3,5,0,0,0], m = 3 // nums2 = [2,4,6], n = 3 int i1 = m - 1; int i2 = n - 1; int cur = nums1.length - 1; while (i2 >.

2021-06-17 20:45:36 64

原创 236. 二叉树的最近公共祖先

* 去以root为根节点的二叉树中查找p、q的最近公共祖先 * ① 如果p、q同时存在于这棵二叉树中,就能成功返回它们的最近公共祖先 * ② 如果p、q都不存在于这棵二叉树中,返回null * ③ 如果只有p存在于这棵二叉树中,返回p * ④ 如果只有q存在于这棵二叉树中,返回q下面的这种写法是错误的/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeN.

2021-05-28 00:06:35 80

原创 5. 最长回文子串——基于扩展中心法的优化

class Solution { public String longestPalindrome(String s) { if (s == null) return null; char[] cs = s.toCharArray(); if (cs.length <= 1) return s; // 最长回文子串的长度(至少是1) int maxLen = 1; // 最长回文子串的开始索引 int begin = 0;

2021-05-27 23:20:47 96

原创 5. 最长回文子串——暴力法---动态规划解法---扩展中心法

暴力法动态规划解法class Solution { public String longestPalindrome(String s) { if (s == null) return null; char[] cs = s.toCharArray(); if (cs.length <= 1) return s; // 最长回文子串的长度(至少是1) int maxLen = 1; // 最长...

2021-05-27 21:41:04 147

原创 226. 翻转二叉树

前序遍历的方式/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNod...

2021-05-16 14:32:02 98

原创 箭头函数中的this的使用

什么时候使用箭头函数问题:箭头函数中的this是如何查找的了?答案:向外层作用域中,一层层查找this,直到有this的定义.<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body><script> // 什么时候使用箭...

2021-05-14 20:13:09 135

原创 箭头函数参数和返回值

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body><script> // 1.参数问题: // 1.1.放入两个参数 const sum = (num1, num2) => { return num1 + num2.

2021-05-14 20:13:00 931

原创 箭头函数的基本使用

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body><script> // 箭头函数: 也是一种定义函数的方式 // 1.定义函数的方式: function const aaa = function () { } /.

2021-05-14 20:12:49 66

原创 动态规划----解121. 买卖股票的最佳时机---最大连续子序列和

2021-05-12 20:34:43 97

原创 121. 买卖股票的最佳时机

class Solution { public int maxProfit(int[] prices) { if (prices == null || prices.length == 0) return 0; // 前面扫描过的最小价格 int minPrice = prices[0]; // 前面扫描过的最大利润 int maxProfit = 0; // 扫描所有的价格 for (int i = 1; i &l...

2021-05-12 20:34:33 73

7.SpringMVC_crud1.zip

SpringMVC-RestfulCRUD 利用SpringMVC做一个CRUD(增删改查)符合Rest风格的; C:Create:创建 R:Retrieve:查询 U:Update:更新 D:Delete:删除 数据库:保存数据; 使用Map,List保存数据之类

2020-03-21

使用ServletContext对象完成网页计数器

当服务器停掉后,重新启动。这个网页计数器又要重新开始计数。这显然不符合逻辑。故需要想一个办法,即使在服务器被停掉后,网页计数器也能正常计数。(使用了io流技术)

2019-04-25

Cookie 学习案例之三天免登录

用Cookie实现 三天免登录,以及session登录练习使用解决null显示问题

2019-04-25

空空如也

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

TA关注的人

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