ARTS 第一周分享
每周完成一个ARTS(也就是 Algorithm、Review、Tip、Share 简称ARTS):
- 每周至少做一个 leetcode 的算法题
- 阅读并点评至少一篇英文技术文章
- 学习至少一个技术技巧
- 分享一篇有观点和思考的技术文章
A Coder,a Programmer,a Developer
Redis 与 Memcached 区别:
Memcached 是多线程,非阻塞 IO 复用的网络模型;Redis 是单线程,多路 IO 复用的网络模型。
Memcached 只支持 String 类型;Redis 支持更丰富的数据类型(主要五种,String、hash、list、set、zset)。
[官网] It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams
Memcached 将数据全部存在内存中;Redis 支持数据的持久化。
Memcached 没有原生的集群模式,需要依靠客户端来实现往集群中分片写入数据;Redis 是原生支持 Cluster 模式的。
时间限制:1秒
空间限制:32768K
一个数组有 N 个元素,求连续子数组的最大和。 例如:[-1,2,1],和最大的连续子数组为[2,1],其和为 3
输入描述:
输入为两行。 第一行一个整数n(1 <= n <= 100000),表示一共有n个元素 第二行为n个数,即每个元素,每个整数都在32位int范围内。以空格分隔。
输出描述:
所有连续子数组中和最大的值。
输入例子1:
3 -1 2 1
输出例子1:
3
SSM 框架整合的思路
1 | <?xml version="1.0" encoding="UTF-8" ?> |
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
1 | public int[] twoSum(int[] nums, int target) { |
事务写在Service层。
为什么不在DAO层?
为什么不在Controller层?
循环依赖的问题:在DI时,如果有两个 class 类,都在 xml 文件中配置,但是如果 classA 是 classB 的属性,classB 同时也是 classA 的属性,那么该怎么处理呢?究竟先注入哪一个呢?
Spring是如何避免循环依赖的?
Spring 的单例对象的初始化主要分为三步:
循环依赖就是两个对象(设为A,B)在①②步时发生冲突的。
Spring使用了一个叫singletonFactories
的三级cache机制,让本该发生A-B-A循环依赖中的B走到第①步时,可以拿到A(虽然A此时并不完整,仅走了①②两步),但足以让B能够走完剩下的②③步。B完成后,A可以继续完成自己的第③步。
如何创建对象的模式,抽象了实例化的过程。
将创建对象的过程进行了抽象和封装,作为客户程序仅仅需要去使用对象,而不再关心创建对象过程中的逻辑。