实习:
数据结构:
计网:
设计模式:
JVM:
Java:
算法:
LC 21 合并有序链表
实习:
项目:
Redis:
Spring Cloud:
Netty:
算法:
LC 515 在每个树行中找最大值
在上面题目基础上,修改条件(奇数最大,偶数最小)(也是尴尬现场,定义了 flag 变量,忘记更新了)
public List<Integer> largestValues(TreeNode root){ List<Integer> res = new ArrayList<>(); Queue<TreeNode> queue = new LinkedList<>(); if (root != null){ queue.offer(root); } boolean flag = false; while (!queue.isEmpty()){ int cur = 0; if (flag){ int cur_size = queue.size(); cur = Integer.MIN_VALUE; for (int i = 0;i < cur_size;i++){ TreeNode x = queue.poll(); cur = Math.max(cur,x.value); if (x.left != null){ queue.offer(x.left); } if (x.right!= null){ queue.offer(x.right); } } }else { int cur_size = queue.size(); cur = Integer.MAX_VALUE; for (int i = 0;i < cur_size;i++){ TreeNode x = queue.poll(); cur = Math.min(cur,x.value); if (x.left != null){ queue.offer(x.left); } if (x.right!= null){ queue.offer(x.right); } } } res.add(cur); flag = !flag; } return res; }
实习:
算法:
剑指42 连续子数组最大和
在上面题目基础上,修改条件(输出子数组,不单单是最大值)
public static void main(String[] args) { int[] nums = {0,2,3,4,-2,-3,9,11}; System.out.println(maxSubArr(nums)); } public static List<Integer> maxSubArr(int[] nums){ if (nums == null || nums.length == 0){ return new ArrayList<>(); } int[][] dp = new int[nums.length][2]; for (int i = 0;i < nums.length;i++){ dp[i][1] = i; } dp[0][0] = nums[0]; int max = dp[0][0]; int start = 0; int end = 0; for (int i = 1;i < dp.length;i++){ if (dp[i - 1][0] > 0){ dp[i][0] = dp[i - 1][0] + nums[i]; dp[i][1] = dp[i - 1][1]; }else { dp[i][0] = nums[i]; dp[i][1] = i; } max = Math.max(dp[i][0],max); if (max == dp[i][0]){ start = dp[i][1]; end = i; } } List<Integer> res = new ArrayList<>(); for (int i = start;i <= end;i++){ res.add(nums[i]); } return res; }
闲聊:
最近频繁面试,把面试官们问我的题目都汇总整理成了一份PDF的文档,内容覆盖了Java、MyBatis、ZooKeeper、Dubbo、Elasticsearch、Memcached、Redis、MySQL、Spring、Spring Boot、Spring Cloud、RabbitMQ、Kafka、Linux 等,如下图:
以上资料已经打包好上传到百度云了,大家自行下载即可:
链接: https://pan.baidu.com/s/1V7bVck1Q6jxjQaoa_deoYg
提取码: 77f5
百度云链接不稳定,随时可能失效~
如果百度云链接失效了的话,请关注博主的微信公众号:Java团长,发送“ 文档 ”也可获取哈~