内容简介:最大水容器、我的五个最糟糕的错误、Spring Cache。Problem:嵌套循环
最大水容器、我的五个最糟糕的错误、Spring Cache。
Algorithm
Problem: Container With Most Water
思路 1
嵌套循环
class Solution {
public int maxArea(int[] height) {
int max = 0;
int l = height.length;
for (int i = 0; i < l; i++) {
for (int j = i + 1; j < l; j++) {
int min = Math.min(height[i], height[j]);
int area = min * (j - i);
if (max < area) {
max = area;
}
}
}
return max;
}
}
思路 2
class Solution {
public int maxArea(int[] height) {
int maxArea = 0, l = 0, r = height.length - 1;
while (l < r) {
maxArea = Math.max(maxArea, Math.min(height[l], height[r]) * (r - l));
if (height[l] < height[r]) {
l++;
} else {
r--;
}
}
return maxArea;
}
}
Review
My Five Worst Bugs: Lessons Learned In System Design 我的五个最糟糕的错误:系统设计中的经验教训。
- 持续沟通,了解真正的需求
- Code Review 与测试非常重要
- 有时错误来自环境的变化
- 生产环境的测试不可少
- 多人协同工作,职责要明确
Tip
Spring Cache 中 @cacheable
和 @CachePut
中 conditon
和 unless
的区别。
unless
属性只能阻止对象放进缓存,但是在这个方法调用的时候,依然会去缓存中进行查找,如果找到了匹配的值,就会返回找到的值,与之不同,如果 condition
的表达式计算结果为 false
,那么在这个方法调用的过程中,缓存是被禁用的。也就是说,不会去缓存进行查找,同时返回值也不会进行缓存中。
Share
最近自如的甲醛房闹得沸沸扬扬,搞得我也去买了甲醛检测仪、空气净化器、紫加黑,以前重来没有想过买空气净化器。这件事情让我觉得生活中潜在的危害才是最严重的。不过有些人为了赚钱真的是够可以的。
以上所述就是小编给大家介绍的《ARTS 第 11 周》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Don't Make Me Think
Steve Krug / New Riders Press / 18 August, 2005 / $35.00
Five years and more than 100,000 copies after it was first published, it's hard to imagine anyone working in Web design who hasn't read Steve Krug's "instant classic" on Web usability, but people are ......一起来看看 《Don't Make Me Think》 这本书的介绍吧!