ARTS-Week002

Algorithm

本周Leetcode算法题:

Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.

Note: You may not slant the container and n is at least 2.

The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.

Example:

Input: [1,8,6,2,5,4,8,3,7]
Output: 49

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/container-with-most-water
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

解答详情:
  • 暴力遍历:
1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public int maxArea(int[] height) {
int maxArea = 0;
int size = height.length;
for (int i = 0; i < size; i++){
for (int j = i + 1; j < size; j++){
maxArea = Math.max(maxArea, Math.min(height[i], height[j]) * (j - i));
}
}
return maxArea;
}
}
  • 双指针法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public int maxArea(int[] height) {
int maxArea = 0, left = 0, right = height.length - 1;
while(left < right){
maxArea = Math.max(maxArea, Math.min(height[left], height[right]) * (right - left));
if(height[left] < height[right]){
left ++;
}else{
right --;
}
}
return maxArea;
}
}

Review

https://medium.com/netflix-techblog/netflix-at-spark-ai-summit-2018-5304749ed7fa

博文讲述了Netflix在2018Spark+AI峰会关于Spark结合ML的一些实践

Tip

背景: 和前端联调前后端分离项目出现跨域问题

现象: 登录请求 401 OPTION请求未通过

解决: 参考https://blog.csdn.net/niugang0920/article/details/79817763

Sharing

交互搜索中的自然语言理解技术

https://yq.aliyun.com/articles/570277?spm=a2c4e.11153959.0.0.68627081h3AoN8