- 博客(14)
- 收藏
- 关注
原创 spring cloud 相关
一. Spring Cloud 解决了哪些问题?与分布式系统相关的复杂性 – 包括网络问题,延迟开销,带宽问题,安全问题。处理服务发现的能力 – 服务发现允许集群中的进程和服务找到彼此并进行通信。解决冗余问题 – 冗余问题经常发生在分布式系统中。负载平衡 – 改进跨多个计算资源(例如计算机集群,网络链接,中央处理单元)的工作负载分布。减少性能问题 – 减少因各种操作开销导致的性能问题。...
2022-03-29 10:57:00
1761
原创 redis内存淘汰
Redis是基于内存的,所以容量肯定是有限的,有效的内存淘汰机制对Redis是非常重要的。当存入的数据超过Redis最大允许内存后,会触发Redis的内存淘汰策略。在Redis4.0前一共有6种淘汰策略。volatile-lru:当Redis内存不足时,会在设置了过期时间的键中使用LRU算法移除那些最少使用的键。(注:在面试中,手写LRU算法也是个高频题,使用双向链表和哈希表作为数据结构)volatile-ttl:从设置了过期时间的键中移除将要过期的volatile-random:从设置了过期时间的
2022-03-29 10:31:22
1302
原创 redis删除策略
惰性删除:只有访问这个键时才会检查它是否过期,如果过期则清除。优点:最大化地节约CPU资源。缺点:如果大量过期键没有被访问,会一直占用大量内存。定时删除Redis会将设置了过期时间的key放入一个独立的字典中,以后会定时遍历这个字典来删除过期的key。Redis默认每秒进行10次过期扫描。过期扫描不会遍历过期字典中所有的key,而是采用一种简单的贪心策略。步骤如下:1.先从过期字典中随机选出20个key2.删除这20个key中已经过期的key3.如果过期的key的比例操作25%,就重复步骤1
2022-03-29 10:30:16
717
原创 SQL优化
基本sql写法:1、少使用select * ,尽量使用具体字段2、对于条件查询等号之类两边的字段类型要一致,字符串不加单引号会索引失效3、尽量少使用order by , 对于需要多个字段排序的可以使用组合索引4、对于group by语句先过滤后分组5、在查询时减少使用null,对字段有多个nukk的可以加添加默认值6、少使用like,对于需要使用的,尽量使用like abc%,不要把匹配符%放字段前面7、在where后少使用函数或者算数运算8、去重的distinct过滤字段要少,避免dis
2022-03-27 14:30:41
122
原创 java OOM触发
java.lang.OutOfMemoryError:GC overhead limit exceeded:当 Java 进程花费 98% 以上的时间执行 GC,但只恢复了不到 2% 的内存,且该动作连续重复了 5 次,就会抛出该错误。简单地说,就是应用程序已经基本耗尽了所有可用内存, GC 也无法回收。...
2022-03-10 09:27:14
727
原创 543. 二叉树的直径
class Solution0 { static int ans; public int diameterOfBinaryTree(TreeNode root) { if(root==null) return 0; ans = 1; depth(root); return ans - 1; } public int depth(TreeNode node) { if (node == null)
2022-03-02 17:00:27
226
原创 347. 前 K 个高频元素
使用堆class Solution { public int[] topKFrequent(int[] nums, int k) { Map<Integer, Integer> occurrences = new HashMap<Integer, Integer>(); for (int num : nums) { occurrences.put(num, occurrences.getOrDefault(num, 0
2022-03-02 16:39:00
88
原创 279. 完全平方数
public static void main(String[] args) { System.out.println(numSquares(2)); } // 13 4 9 public static int numSquares(int n) { int[] f = new int[n + 1]; for (int i = 1; i <= n; i++) { int minn = Integer...
2022-03-02 15:42:18
95
原创 239.滑动窗口最大值
class Solution2 { public static void main(String[] args) { int[] nums = {1, 3, -1, -3, 5}; int[] numd = {0, 1, 2, 3, 4}; int[] ints = maxSlidingWindow(nums, 3); System.out.println(Arrays.toString(ints)); } publ
2022-03-02 14:52:11
86
原创 打家劫舍 leetcode 198
class Solution1 { public int rob2(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int length = nums.length; if (length == 1) { return nums[0]; } int[] dp = new in
2022-03-02 11:57:25
160
原创 实现前缀树-leetcode 208
class Trie { private Trie[] children; private boolean isEnd; public Trie() { children = new Trie[26]; isEnd = false; }// word work public void insert(String word) { Trie node = this; for (int i = 0; .
2022-03-02 11:56:01
133
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人