- 博客(76)
- 资源 (6)
- 收藏
- 关注
原创 双指针相关算法
给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素。元素的顺序可能发生改变。然后返回 nums 中与 val 不同的元素的数量。slow指针走过的是已经处理好的元素。fast走过的是判断过的元素。
2026-03-11 13:49:38
41
原创 ConcurrentHashHap
但基于 put 的复合业务逻辑可能不是线程安全的,需要开发者额外使用同步机制(如 synchronized 块)或 ConcurrentHashMap 提供的原子方法(如 computeIfAbsent、merge 等)来保证。ConcurrentHashMap.put() 方法本身是线程安全的,不会破坏内部数据结构。
2026-01-26 11:02:59
36
原创 类锁和对象锁
那么不能用对象锁,加在整个类上粒度又太大了,一个用户的任务会影响其他用户也被锁住。这样一个对象获取到,另一个就获取不到了,因为就一个是共享的锁。再去用不同的实例去调用时,是对当前对象加锁,test1拿到锁之后,test2也能拿到,是不同实例的锁,所以锁的只是当前调用的对象。test1调用方法获得锁,test2再调用的时候获取不到了,因为锁在了这个类上,那么整个这个类的实例在调用的时候都调用不了。对象锁是基于对堆内存内对象的头部加锁信息;如果是用私有的lock也是一样的,要是对整个类上锁就加static,
2026-01-26 11:01:38
75
原创 hashmap
初始容量,table 数组大小是由 capacity 这个参数确定的,默认是16,也可以构造方法时传入,最大限制是1<<30;向上最接近2的幂值。右移16位 分为高半区低半区做异或,加大低位的随机性,也掺杂高位的部分特征。如果映射到同一个位置时,发生冲突,尾插法形成链表,大小超过8个会。当size大于threshold会resize为2倍。转为红黑树,为了查询效率,节点小于6时再转为链表。用散列值对长度取模,作为下标,用位运算效率高。这样把key,value映射到表中一个位置。hash扰动函数来降低冲突。
2026-01-26 10:23:07
42
原创 线程安全:原子性指令重排可见性
没刷到主内存的时候,别的线程拿到的都是不对的,有点像脏读啊, 那就不一致了呗,不对了呗。2.线程2拿到i=0,执行i++;得到i=1,赋值给主内存,其实可能还没给到主内存。1.线程1拿到i=0 没有执行i++的时候,线程2抢着执行。就是这个操作不是一个整体,执行的过程中被别的线程打断了。可见性:主内存就是内存,工作内存就是线程自己的缓存。得到i=1,赋值给主内存。volatile就是禁止指令重排,和保证可见性的。4.2次本来结果为2,但是因为并发导致是1。例子就是多个线程执行i++, 最后得到的结果。
2026-01-22 11:53:05
41
原创 java锁升级
偏向锁就是之前获取过的就还给你,就认为是所谓的锁上了,就是有访问权了。轻量就是去修改一个字段的值,如果成功了就相当于获取到访问权了,这里应该是硬件的cas作修改看能不能改成功,然后并不是真正阻塞了。这些都是默认说没人来争抢,那我就不用加重锁,如果这时又线程来竞争,那就不行了,就得再升级。因为加锁会导致线程切换,系统从用户态转到内核态,影响性能。所以先尝试偏向锁 轻量锁 自旋 然后才加重锁.锁是在字节码里通过获取monitor实现的。首先乐观锁不是真的锁。
2026-01-22 11:00:51
43
原创 Spring的AOP失效场景
3. 异常类型不匹配 抛出checked exception 不rollback for Exception class。cglib 类和接口 创建其子类的方式 都不支持final的 性能好 但是创建花的时间多。4. requires_new传播机制时,外层的回滚不回影响本来的事务,被挂起的。5.@Async异步方法AOP拦截器无法跟踪到这些新线程中的方法调用。2.非事务方法调用事务方法 内部调用绕过了代理对象。动态生成代理类的字节码,运行时反射创建字节码文件。不侵入原有的逻辑 并且代码逻辑可复用。
2026-01-21 17:56:20
127
转载 AutocompleteSystem
Note:MANY DETAILS ARE MISSED:If less than 3, return as many as it. So it could be NPE when queue.poll().getKey()Use alphabetical order if times are same. So in the queu need to compare value first then compare string.Logically it needs to set chi
2021-08-11 23:21:37
165
原创 2021-06-20微软面试
package msinterview;public class CoinTransition {static int count = 0;public static void main(String[] args) {int[] coins = new int[] {1, 1, -1}; System.out.print(maxTransition(coins));}// 1是正面 -1是花static int maxTransition(int[] coins) { for (i
2021-06-20 12:36:02
197
原创 【刷题】leetcode 355. Design Twitter
public class Twitter { Map<Integer, Set<Integer>> fans = new HashMap<>(); Map<Integer, LinkedList<Tweet>> tweets = new HashMap<>(); int cnt = 0; public void postTweet(int userId, int tweetId) { i
2020-10-08 20:43:42
279
原创 【刷题】leetcode 113 path sum II
Example:Given the below binary tree and sum = 22, 5 / \4 8/ / 11 13 4/ \ / 7 2 5 1Return:[[5,4,11,2],[5,8,4,5]]/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; *
2020-10-08 15:12:53
161
原创 【刷题】leetcode 621 task schedule
Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task
2020-10-08 15:07:51
139
原创 【刷题】leetcode 763 partition labels
A string S of lowercase English letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.Example 1:Input: S = “ab
2020-10-08 15:02:44
153
原创 【刷题】Leetcode 394 decode string
用栈public class Solution { public String decodeString(String s) { String res = ""; Stack<Integer> countStack = new Stack<>(); Stack<String> resStack = new Stack<>(); int idx = 0; while (id
2020-10-08 14:59:04
125
原创 minimum depth tree
class Solution {// 从叶子节点往上遍历,最终剩下的是结果public List findMinHeightTrees(int n, int[][] edges) {List res = new ArrayList<>();if (n == 1) {res.add(0);return res;}int[] degree = new int[n];Map<Integer, Set> map = new HashMap<>();for (i
2020-09-20 20:42:50
108
原创 [刷题]连续整数
15=1+2+3+4+515=4+5+615=7+81.如果输入n是奇数,那连续整数可以表示为:n = (n-1)/2 + (n+1)/22.如果输入n是偶数,分两种情况:情况1:n一直除以2,如果最终结果是奇数(最终不是1),那n可以是连续奇数组成情况2:n一直除以2,结果一直是偶数,那无法形成连续的奇数,即该数是2的n次方...
2020-08-03 15:18:51
471
原创 刷题:(0,0)到(i,j)最大值
题目:2 31 2 31 0 2最大值:8DP算法public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int row = sc.nextInt(); int column = sc.nextInt(); int[][] dpMat = new int[row][column]
2020-07-31 18:00:57
297
原创 【刷题】Leetcode 171. Excel Sheet Column Number
有一段时间没有刷题了,因为我已经拿到**菊厂**的offer啦! 回头看写的这些博客,都是对做过的的题的总结,代码规范,时间复杂度,注释等写的还可以更好一些。 我知道自己的总结和格式都*不够*到位和漂亮,没有特别认真的去书写,都是做完题草草的留下来了而已。 所以,今后还是会更多的总结,包括这一年左右国内大厂的面经,分享给可能和我一样拧巴一样努力奋进想要铁杵成针的童鞋。 今天写这道题,是因为这是道面试原题哦!A -> 1B -> 2C -> 3…Z...
2020-05-26 15:51:57
170
原创 【刷题】Leetcode 146. LRU Cache
class LRUCache { HashMap<Integer, Node> map; int capacity; int count; Node head; Node tail; public LRUCache(int capacity) { map = new HashMap<Integer, Node>...
2020-04-11 21:04:37
207
原创 【刷题】Leetcode 300. Longest Increasing Subsequence
3 10 1 8 5 6 9 4 dp[]: 1 2 1 2 2 3 4 2public class Solution { public int lengthOfLIS(int[] nums) { if (nums.length == 0) { return 0; } int[] dp =...
2020-03-24 19:55:54
129
原创 虚拟化和云计算
!](https://img-blog.csdnimg.cn/20200310174208355.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE5NDUwOTIx,size_16,color_FFFFFF,t_70)
2020-03-10 17:43:22
158
原创 英语(from little sheldon)
beside herself 气疯了,着急be a good sport 有风度you have the floor 你可以说了bluff 唬人on the heels of 紧接着
2020-02-29 18:57:04
305
转载 spring容器实现
Spring容器的简单实现(IOC原理)引言:容器是什么?什么是容器?Spring容器又是啥东西?我给Spring容器一个对象名字,为啥能给我创建一个对象呢?一、容器是装东西的,就像你家的水缸,你吃饭的碗等等。 java中能作为容器的有很多,例如Map,List,数组.....还有好多二、Spring 容器的核心就是一个Map集合(可能不是很准确,见谅!)Map<String,...
2020-02-28 17:23:12
188
原创 你问我都学了啥
jvm: https://www.bilibili.com/video/av70166821/?spm_id_from=333.788.videocard.1mysql高级: https://www.bilibili.com/video/av68633494/?p=44&t=31spring: https://www.bilibili.com/video/av71252572?p=2...
2020-02-28 13:56:23
168
原创 计算机网络
广域网: https://www.bilibili.com/video/av40760446?from=search&seid=15674602669622404275socket编程:https://www.bilibili.com/video/av69214367?p=8局域网:https://www.bilibili.com/video/av9876107?p=2香农公式:ht...
2020-02-22 17:53:41
130
原创 计算机原理???
制作8位计算机:https://www.bilibili.com/video/av77065201?p=62计算机如何读取代码:https://www.bilibili.com/video/av62271485How a CPU works: https://www.bilibili.com/video/av9667986?from=search&seid=1517593687...
2020-02-22 17:50:23
163
原创 93. Restore IP Addresses
Example:Input: “25525511135”Output: [“255.255.11.135”, “255.255.111.35”]class Solution { public List<String> restoreIpAddresses(String s) { List<String> list = new ArrayList();...
2019-12-25 15:23:17
115
原创 19. Remove Nth Node From End of List
/**Definition for singly-linked list.public class ListNode {int val;ListNode next;ListNode(int x) { val = x; }}*/class Solution {public ListNode removeNthFromEnd(ListNode head,...
2019-12-25 15:22:33
111
原创 牛客网 华为编程
Leetcode 37class Solution { public void solveSudoku(char[][] board) { if(board.length == 0 || board == null) return; helper(board, 0); } public boolean helper(...
2019-12-22 11:57:30
148
原创 【刷题】Leetcode 347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]class Solution { ...
2019-12-18 19:16:49
167
原创 【刷题】Leetcode 746. Min Cost Climbing Stairs
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of t...
2019-12-09 15:55:11
127
基于matlab的车牌识别
2016-02-17
基于android的二维码识别系统研究与实现
2016-02-17
zuoyexitong .zip
2020-03-06
52001CC1C8 Java 实践17-18-3.zip
2020-03-06
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅