左耳听风ARTS第1周
20190317开始参加ARTS的项目,希望自己可以坚持下去。每周完成一个ARTSAlgorithm、Review、Tip、Share1、每周至少做一个leetcode的算法题, (给自己的目标是要分析时间复杂度)2、阅读并点评至少一篇英文技术文章3、学习至少一个技术技巧4、分享一篇有观点和思考的技术文章Week 1:Algorithm记得自己几年前刷过一些题,...
20190317开始参加ARTS的项目,希望自己可以坚持下去。
每周完成一个ARTS
Algorithm、Review、Tip、Share
1、每周至少做一个leetcode的算法题, (给自己的目标是要分析时间复杂度)
2、阅读并点评至少一篇英文技术文章
3、学习至少一个技术技巧
4、分享一篇有观点和思考的技术文章
Week 1:
Algorithm
记得自己几年前刷过一些题, 但是没能坚持下来。 这次重新来刷题, 感触很深。
先找了一个最简单的刷
1. Two Sum
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].
原来碰到这样的问题不自然的就想到了嵌套循环,于是就写出了如下的程序:
class Solution {
public int[] twoSum(int[] nums, int target) {
for (int i=0; i<nums.length-1; i++){
for (int j = i+1; j<nums.length; j++){
if (nums[i]+nums[j] == target){
int[] result = new int[2];
result[0] = i;
result[1] = j;
return result;
}
}
}
return null;
}
}
通过查看leetcode上其他人的解决方案, 发现自己工作中经常用到的一个方法, 就是先循环放入map,然后再循环和map比较。自己这么用的时候很少考虑为什么这么用,这么用的好处是什么? 通过这个题目和大家的分析讨论, 才意识到这是时间复杂度的问题。
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (int i=0; i<nums.length-1; i++){
map.put(nums[i], i);
}
for (int j = 0; j<nums.length; j++){
int com = target-nums[j];
if (map.containsKey(com) && map.get(com) != j){
return new int[] { j, map.get(com) };
}
}
return null;
}
}
Review:
由于目前在用nightwatchjs做端到端的前端自动化测试, nightwatch国内资料比较少, 所以只有阅读期官网的文档, 但是对于Working with Page Object , 版本由v0.9.21 升级到v1.0.19之后之前的功能有几处改动, 首先定义了页面文件的路径之后, 在其下只能建立一级子文件夹, 二级就找不到, 于是去github上用自己蹩脚的英语去提issue。 作者把这标记为bug了。(很激动)
https://github.com/nightwatchjs/nightwatch/issues
Tip
说来惭愧,工作这么久, 居然很少看源码, 最近才开始看java的源码, 了解了java8的新特性,细节了解了ArrayList的自动扩容给自己的目标今年要了解java、spring 源码。
Share:
前端自动化测试HTML5的CAVAS。 我们的应用是往canvas上放置元素, 但是无法具体定位到canvas上存在什么元素, 于是就用了图像对比的方式, 使用node-resemble-js 第三方的库, 在运行的时候截取图片和基准库中的图片做相似度比较, 给出一个容忍百分比。
第一次打卡不知道如何写起, 希望自己贵在坚持, 越来越好!
更多推荐
所有评论(0)